Mandrill:SMTP错误:无法连接到服务器:连接超时(110)

时间:2015-04-14 02:35:12

标签: smtp phpmailer mandrill

我有以下配置,可在一小时内向50位客户发送群发电子邮件。

SMTP提供商:Mandrill

每小时配额:380封电子邮件/小时

邮箱声誉:好而不是垃圾邮件

PHPMailer:第5版

问题:当我执行脚本时,有时它会向50个客户中的每个客户发送邮件,但有时会停止发送邮件说:

SMTP错误:无法连接到服务器:连接超时(110)

它会自动恢复并向剩余的客户发送电子邮件。

我的代码

    {
    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->SMTPDebug = 4;
    $mail->Debugoutput = 'html';
    $mail->Host = SMTP_HOST;
    $mail->Port = 25;
    $mail->SMTPAuth = true;
    $mail->Username = SMTP_USERNAME;
    $mail->Password = SMTP_PASSWORD;
    $mail->setFrom(SMTP_USERNAME, SMTP_NAME);

    For Loop{
    $msgHTML = "<table width='500px;' align='center'>";
    $msgHTML .= "<tr><td>Dear Customer</td></tr>";
    $msgHTML .= "</table>";


    $mail->addReplyTo();
    $mail->addAddress();
    $mail->Subject = 'Loan Request Follow Up from xyzdummy.com.';
    $mail->msgHTML($msgHTML);
    $mail->AltBody = 'This is a plain-text message body';
    try{
    $mail->send();
    echo "Mail Sent to ->".$forloop[$j]['EmailId'] ;
    }
    catch (phpmailerException $e) 
    { 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer
    echo "Mail Failed to ->".$forloop[$j]['EmailId'] ;
    }


    $mail->clearAddresses();
    $mail->clearCCs();
    $mail->clearBCCs();     
    }   
    }

时的输出
            Connection: opening to smtp.mandrillapp.com:25, t=10, opt=array ()
            Connection: opened
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "220 smtp.mandrillapp.com ESMTP"
            SMTP -> get_lines(): $data is "220 smtp.mandrillapp.com ESMTP"
            SERVER -> CLIENT: 220 smtp.mandrillapp.com ESMTP
            CLIENT -> SERVER: EHLO smtp.mandrillapp.com
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "250-relay-2.ap-southeast-1.mandrill-relay-prod"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod"
            SMTP -> get_lines(): $str is "250-PIPELINING"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING"
            SMTP -> get_lines(): $str is "250-SIZE 26214400"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400"
            SMTP -> get_lines(): $str is "250-STARTTLS"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS"
            SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN"
            SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES"
            SMTP -> get_lines(): $str is "250 8BITMIME"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES250 8BITMIME"
            SERVER -> CLIENT: 250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES250 8BITMIME
            CLIENT -> SERVER: AUTH LOGIN
            SMTP -> get_lines(): $data was ""
            bl abla
            CLIENT -> SERVER: 
            CLIENT -> SERVER: .
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "250 2.0.0 Ok: queued as D1D682A0B20"
            SMTP -> get_lines(): $data is "250 2.0.0 Ok: queued as D1D682A0B20"
            SERVER -> CLIENT: 250 2.0.0 Ok: queued as D1D682A0B20
            CLIENT -> SERVER: QUIT
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "221 2.0.0 Bye"
            SMTP -> get_lines(): $data is "221 2.0.0 Bye"
            SERVER -> CLIENT: 221 2.0.0 Bye
            Connection: closed



            Connection: opening to smtp.mandrillapp.com:25, t=10, opt=array ()
            SMTP ERROR: Failed to connect to server: Connection timed out (110)
            SMTP connect() failed.
            SMTP connect() failed.

            Connection: opening to smtp.mandrillapp.com:25, t=10, opt=array ()
            SMTP ERROR: Failed to connect to server: Connection timed out (110)
            SMTP connect() failed.
            SMTP connect() failed.


            Connection: opening to smtp.mandrillapp.com:25, t=10, opt=array ()
            SMTP ERROR: Failed to connect to server: Connection timed out (110)
            SMTP connect() failed.
            SMTP connect() failed.

            SMTP ERROR: Failed to connect to server: Connection timed out (110)
            SMTP connect() failed.
            SMTP connect() failed.

            Connection: opening to smtp.mandrillapp.com:25, t=10, opt=array ()
            Connection: opened
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "220 smtp.mandrillapp.com ESMTP"
            SMTP -> get_lines(): $data is "220 smtp.mandrillapp.com ESMTP"
            SERVER -> CLIENT: 220 smtp.mandrillapp.com ESMTP
            CLIENT -> SERVER: EHLO smtp.mandrillapp.com
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "250-relay-2.ap-southeast-1.mandrill-relay-prod"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod"
            SMTP -> get_lines(): $str is "250-PIPELINING"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING"
            SMTP -> get_lines(): $str is "250-SIZE 26214400"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400"
            SMTP -> get_lines(): $str is "250-STARTTLS"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS"
            SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN"
            SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES"
            SMTP -> get_lines(): $data was "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES"
            SMTP -> get_lines(): $str is "250 8BITMIME"
            SMTP -> get_lines(): $data is "250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES250 8BITMIME"
            SERVER -> CLIENT: 250-relay-2.ap-southeast-1.mandrill-relay-prod250-PIPELINING250-SIZE 26214400250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES250 8BITMIME
            CLIENT -> SERVER: AUTH LOGIN
            SMTP -> get_lines(): $data was ""
            bl abla
            CLIENT -> SERVER: 
            CLIENT -> SERVER: .
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "250 2.0.0 Ok: queued as D1D682A0B20"
            SMTP -> get_lines(): $data is "250 2.0.0 Ok: queued as D1D682A0B20"
            SERVER -> CLIENT: 250 2.0.0 Ok: queued as D1D682A0B20
            CLIENT -> SERVER: QUIT
            SMTP -> get_lines(): $data was ""
            SMTP -> get_lines(): $str is "221 2.0.0 Bye"
            SMTP -> get_lines(): $data is "221 2.0.0 Bye"
            SERVER -> CLIENT: 221 2.0.0 Bye
            Connection: closed

我可以很好地运行发送脚本,然后一个接一个地连续运行2到3次。它工作正常但突然无法连接

我问了Mandrill smtp failures的评论。我被建议在网站上提出一个新问题。

除了添加

,我不知道在哪里修复

$ phpMailer-&gt; SMTPKeepAlive = true;和$ phpMailer-&gt; SmtpClose();在for循环之前和之后。

但是,我不确定这是否是正确的做法?

你可以高度重视解决上述问题。

由于

2 个答案:

答案 0 :(得分:0)

这看起来像是一个mandrill问题 - 你在PHPMailer中做的一切都是正确的。他们可能正在使用循环DNS在服务器池上传播连接,并且其中一个或多个可能已关闭。如果他们的服务器工作不正常,那么你最终无法做任何事情。唯一真正的后备是您使用本地邮件服务器并将其设置为通过mandrill进行中继。这将负责排队和重试发送,并使您的应用程序能够继续处理其他事情,因为发送将是异步的。

你绝对应该使用SMTPKeepAlive - 它会使发送效率更高,并降低发生此问题的可能性(因为它只会使用一台服务器)。

答案 1 :(得分:0)

根据您的本地环境,这也可能是因为您的托管服务提供商或ISP限制了出站SMTP连接。有些人有速率限制,或者如果超出某些限制,将重定向连接。您也可能有smtp.mandrillapp.com的陈旧DNS记录,这会导致您的系统尝试访问不再用于该主机名的IP地址上的smtp.mandrillapp.com。您可以使用Wireshark之​​类的工具来实际跟踪您要连接(或尝试连接)的特定IP。 PHPMailer可能还有更详细的日志记录,但您希望查看有关 您尝试连接以确定问题的更多详细信息。