Page 1 of 1

using mail() in a loop

Posted: Sun May 05, 2013 3:12 pm
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 );
}

Re: using mail() in a loop

Posted: Sun May 05, 2013 6:25 pm
by McInfo
On the second iteration of the loop, the "**name**" token no longer exists in $messy.

Re: using mail() in a loop

Posted: Sun May 05, 2013 8:55 pm
by Da_Elf
oooooooohhhhh. right. that makes sense. simple little things like that.