using mail() in a loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Da_Elf
Forum Commoner
Posts: 81
Joined: Mon Dec 29, 2008 12:31 pm

using mail() in a loop

Post by Da_Elf »

i used some arrays but somehow they wont clear each loop
ive setup the subject, from and content type for the mail() option first outside of the loop then i start pulling info from a database to use in the loop. To each of the email addresses it uses the wrong information. it keeps repeating the name of the first person pulled from the database even though i unset the array

Code: Select all

<?php
$messy= $_POST['emailmessage']
$subject = "$emailertopic";
$headers = "From: le1248 <$admyaddy>\r\nReply-To:".$admyaddy."\r\n";
$headers .= "Content-Type: text/html; charset=\"UTF-8\"\r\nContent-Transfer-Encoding: 8bit";

$result = mysql_query("SELECT email, name FROM person ORDER BY id ASC", $dbConn);
while ($resultf= mysql_fetch_array($result , MYSQL_ASSOC)) {
$name= $resultf['name '];
$to= $resultf['email'];
$chrpfrom = array("**name**","\n");
$chrpto = array($name,"<br />");
$chrp = array_combine($chrpfrom, $chrpto);
$messy = strtr($messy, $chrp);
unset($chrpfrom);unset($chrpto);unset($chrp );
ob_start();?>
This is the message<br>
_________________<br>
<?=$messy?>
_________________<br>
<?php 
$message = ob_get_clean();
mail( $to, $subject, $message, $headers );
}
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: using mail() in a loop

Post by McInfo »

On the second iteration of the loop, the "**name**" token no longer exists in $messy.
Da_Elf
Forum Commoner
Posts: 81
Joined: Mon Dec 29, 2008 12:31 pm

Re: using mail() in a loop

Post by Da_Elf »

oooooooohhhhh. right. that makes sense. simple little things like that.
Post Reply