I'm trying to set up a script which send a mail pr. reciever in a loop like this:
require_once("emails/themail.php");
foreach($currUserids as $currUserid){
$sql="SELECT * FROM ".$prefix."_users WHERE new_userid = '$currUserid'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$reEmail = $row['email'];
$reFname = $row['fname'];
$reLname = $row['lname'];
////////////// SEND MAIL START ////////////////
themail();
///////////// SEND MAIL END ///////////////
}
themail.php:
$mail = new PHPMailer();
$mail->IsSendmail(); // telling the class to use SendMail transport
$mail->From = 'my@domain.com';
$mail->FromName = 'Me';
$mail->AddAddress($memail, $mfname.' '.$mlname);
$mail->Subject = "".$cfname." ".$clname." wrote an email to you";
////////// START EMAIL //////////
/* The email contenet here */
$body = $textHTML;
////////// END EMAIL //////////
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
//echo "Message sent!";
}
Now, everything works fine when sending to one reciever, but when I want to send to multiple recievers they each recieves duplicate mails for the number of recivers... How do I get passed this???
Please help... Thanks