I’ using phpmailer to send out newsletters and that allmost works greate but one problem. I want individuel names in my emails and I get that if I do as my script below, but the second reciever recieves an email with the same content twice, like a duplicate of the email sent to the first reciever and the third reciever gets duplicates of the first and the second and so on…
Here is what i have so far:
include_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->Host = "mail.mypage.com"; // SMTP server
$mail->IsSendmail(); // telling the class to use SendMail transport
$mail->From = 'me@mypage.com';
$mail->FromName = 'My Name';
$sql="SELECT * FROM ".$prefix."_table WHERE newsletter=1";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$mail->Subject = "This is a test";
$textHTML = "Hello ".$row['name'].",<br><br>";
$textHTML .= "This is an test message... Just testing!";
$body = $textHTML;
$mail->AltBody .= "To view the message, please use an HTML compatible email viewer!";
$mail->AddAddress($row['email'], $row['name']);
$body = eregi_replace("[\\]",'',$body);
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo 'Message sent to: '.$row['email'].'<br>';
}
$mail->ClearAddresses();
$mail->ClearAttachments();
}
Its tearing me a part so please help…