[英]PHP Do While Sending Emails
我有以下代码,该代码发送电子邮件,但它将一封电子邮件嵌入另一封电子邮件中,而不是分别发送,输出也在下面。
有什么想法吗?
H。
电子邮件输出
SMTP Test Email Message
Dear Gary,
Dear Jaime,
Test Message
Here is a quick email test to see what it comes through like. Link: =
Test
Does it do formatting correctly and what is the situation with dual = names appearing etc?
Kind regards,
Gary.
Link: http://
Test
Does it do formatting correctly and what is the situation with dual names appearing etc?
Kind regards,
Gary.
程式码片段
do {
$dear = "<font face='Arial' size='2'>Dear " . $row["forename"] . ",<br><br></font>";
$email_body = $dear . "<font face='Arial' size='2'>" . stripslashes($body) . "</font><br><br><font face='Arial' size='2'>" . $linky . " <a href='" . $row["link"] . "'> " . $row["link"] . "</a> </font> <br><br><font face='Arial' size='2'>" . stripslashes($body2) . "</font>";
$subject = $sub;
$bcc = "blob.blob@blob.co.uk";
$recipients = $row["email"].",".$bcc;
// Constructing the email
$sender = $bcc;
$recipient = $recipients;
$subject = $subject;
$html = $email_body;
$crlf = "\n";
$headers = array(
'To' => $row["Mail"],
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
//$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);
// SMTP authentication params
$smtp_params["host"] = "scr.emserv.com";
$smtp_params["port"] = "25";
$smtp_params["auth"] = true;
$smtp_params["username"] = "blob.blob@blob.co.uk";
$smtp_params["password"] = "blob";
// Sending the email using smtp
$mail =& Mail::factory("smtp", $smtp_params);
sleep(2);
$result = $mail->send($recipient, $headers, $body);
for($i=0;$i<$elements1;$i++){
$bar1->increase(); //calls the bar with every processed element
$bar1->setMessage('Sending emails (2 second delay between each): '.(($i+1)*$sent).'%');
}
if($row["sent"]=='YES'){
$reminder = $row["reminder"] + 1;
$update = mysql_query("UPDATE $table SET reminder = $reminder WHERE respondent_id = " . $row["respondent_id"] . " ") or die("Could not update record<br>".mysql_error());
}else
$update = mysql_query("UPDATE $table SET sent = 'YES' WHERE respondent_id = " . $row["respondent_id"] . " ") or die("Could not update record<br>".mysql_error());
} while ($row = mysql_fetch_assoc($results));
$bar1->setMessage('Emails have now been sent: 100%');
}
您看到此问题的原因是您没有清除$ body变量。 每次循环时,基本上都将其附加到此行的$ email_body变量中:
$email_body = $dear . "<font face='Arial' size='2'>" . stripslashes($body) ...
再往下,您将$ body设置为整个消息:
$body = $mime->get();
get()以字符串形式返回整个消息 。 您原本会使用$ body也没有任何意义,因为直到在我列出的第一行之后,它才在do while循环中初始化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.