使用PHP邮件发送2封电子邮件失败 [英] Sending 2 emails with PHP mailer fails
问题描述
// SMTP服务器详细信息
$ mail-> IsSMTP();
$ mail-> Host =mail.hostserver.com;
$ mail-> SMTPAuth = false;
$ mail->用户名= $ myEmail; // SMTP usr
$ mail-> Password =****; // SMTP pass
$ mail-> SMTPKeepAlive = true;
$ mail-> From = $ patrickEmail;
$ mail-> FromName =***;
$ mail-> AddAddress($ email,$ firstName。$ lastName);
$ mail-> WordWrap = 50;
$ mail-> IsHTML(true);
$ mail-> Subject = $ client_subject;
$ mail-> Body = $ client_msg;
if($ mail-> Send())
{
$ mail-> ClearAllRecipients();
$ mail-> ClearReplyTos();
$ mail-> ClearCustomHeaders();
...
$ mail-> From =DO_NOT_REPLY @ ...;
$ mail-> FromName =****;
$ mail-> AddAddress($ ToEmail1,***); //至:(收件人)。
$ mail-> AddAddress($ ToEmail2,***); //至:(收件人)。
$ mail-> WordWrap = 50;
$ mail-> IsHTML(true);
$ mail-> Subject = $ notification_subject;
$ mail-> Body = $ notification_msg;
if($ mail-> Send())
{
...
第一封电子邮件发送正常。第二个没有。可能是这种行为的原因?我错过了某种重置?
更新:使用不同的邮件服务器似乎工作,显然这是一个该特定邮件服务器导致问题。任何想法可能是什么?
一些提供商对特定时间段内可以发送的消息数量施加限制。要确定您的问题是否取决于提供商速率限制,您应该尝试在第一次发送后添加暂停。例如:
if($ mail-> Send()){
sleep(10) ; // Seconds
...
if($ mail-> Send()){
...
}
}
然后,逐渐降低睡眠时间,您应该可以确定哪个速率限制。
I am rather puzzled with this one.
//SMTP servers details
$mail->IsSMTP();
$mail->Host = "mail.hostserver.com";
$mail->SMTPAuth = false;
$mail->Username = $myEmail; // SMTP usr
$mail->Password = "****"; // SMTP pass
$mail->SMTPKeepAlive = true;
$mail->From = $patrickEmail;
$mail->FromName = "***";
$mail->AddAddress($email, $firstName . " " . $lastName);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $client_subject;
$mail->Body = $client_msg;
if($mail->Send())
{
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
$mail->ClearCustomHeaders();
...
$mail->From = "DO_NOT_REPLY@...";
$mail->FromName = "****";
$mail->AddAddress($ToEmail1, "***"); //To: (recipients).
$mail->AddAddress($ToEmail2, "***"); //To: (recipients).
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $notification_subject;
$mail->Body = $notification_msg;
if($mail->Send())
{
...
The first email sends fine. The second one doesn't. What could be the reason for that behavior? Am I missing some kind of reset?
Update: using a different mail server seems to work so apparently it's a setting of that specific mail server causing problems. Any idea what that could be?
Some providers impose restrictions on the number of messages that can be sent within a specific time span. To determine if your problem depends by a provider "rate limit", you should try to add a pause after the first send. For example:
if ($mail->Send()) {
sleep(10); // Seconds
...
if ($mail->Send()) {
...
}
}
Then, by progressively lowering the sleep time, you should be able to determine which is the rate limit.
这篇关于使用PHP邮件发送2封电子邮件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!