當我嘗試使用PHPMailer從while循環發送電子郵件時,它有時會向每個收件人發送2個郵件(有時候是3個副本)。在while循環中發送電子郵件
這是我的代碼。你認爲它有問題嗎?
$list = $_POST['list'];
$items = rtrim($_POST['items'],",");
$query = "SELECT * FROM `mail` WHERE `ID` IN ($items)";
$result = mysql_query($query);
$from = "[email protected]";
$fromname = "mysite";
$mail = new PHPMailer(true);
$mail->IsSendmail();
$mail->From = $from;
$mail->FromName = $fromname;
$mail->Subject = "Your subscription was confirmed";
while ($row = mysql_fetch_array ($result))
{
// HTML body
$body .= "<p>Hi ". $row['name'] ." <br /><br />";
$body .= "Your subscription request to " . $l_name ."'s list was confirmed.<br /><br />";
$body .= "Thank You !<br /><br />";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row['email']);
$mail->Send();
$mail->ClearAddresses();
}
你覺得我應該把那個mail->send();
出while循環,並得到所有從數組電子郵件?
或者你認爲這是MySQL查詢的問題?我發現數據庫沒有問題,但我知道(可以說有2個郵件在數組中)它通常發送第一封電子郵件,但第二個發佈與公佈的$ body變量,我的意思是發送$身體變量dublicated。
FIX:嘿,我完成了,我只是加了$body = "";
,它現在完美了!
你在數據庫中的重複。 – David 2009-11-12 12:59:31
我同意戴維。檢查你的數據庫。 – mauris 2009-11-12 13:02:00
是的,我和大衛一起去。檢查您的數據庫 – sathish 2009-11-12 13:03:10