首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mandrill : SMTP错误:连接到服务器失败:连接超时(110)

Mandrill : SMTP错误:连接到服务器失败:连接超时(110)
EN

Stack Overflow用户
提问于 2015-04-14 02:35:12
回答 2查看 1.4K关注 0票数 0

我有以下配置发送大量电子邮件给50个客户在一个小时内。

SMTP提供程序: Mandrill

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

邮箱信誉:良好而非垃圾邮件

PHPMailer :第5版

发布:当我执行脚本时,有时它会向50个客户发送邮件,而有时则停止发送邮件:

SMTP错误:未能连接到服务器:连接超时(110)

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

我的代码

代码语言:javascript
复制
    {
    $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();     
    }   
    }

输出时

代码语言:javascript
复制
            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->SMTPKeepAlive = true;$phpMailer->SmtpClose();for循环前后。

不过,我不知道这是否正确的做法?

您对解决上述问题的指点将得到高度重视。

谢谢

EN

回答 2

Stack Overflow用户

发布于 2015-04-14 06:35:11

这看起来确实是个演习问题--你在PHPMailer中做的一切都是对的。他们可能正在使用循环DNS在一个服务器池上扩展连接,其中一个或多个服务器可能被关闭。如果他们的服务器不能正常工作,那么在您的终端就没有什么可以做的了。唯一真正的退路是使用本地邮件服务器,并将其设置为通过mail中继。这将处理排队和重试发送,并使您的应用程序能够继续其他事情,因为发送将是异步的。

您肯定应该使用SMTPKeepAlive --它将使发送更加高效,并减少出现此问题的可能性(因为它只使用一台服务器)。

票数 0
EN

Stack Overflow用户

发布于 2015-04-14 13:18:45

根据本地环境的不同,这也可能是因为宿主提供商或ISP限制出站SMTP连接。有些有速率限制,或者在超过某些限制时会重定向连接。您还可能有smtp.mandrillapp.com的过时DNS记录,这将导致您的系统试图访问不再用于该主机名的IP地址上的smtp.mandrillapp.com。您可以使用像Wireshark这样的工具来实际跟踪正在连接(或试图连接到)的特定IP。PHPMailer中也可能有更详细的日志记录,但是您可能希望看到更多关于您试图连接到哪里以确定问题的详细信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29618251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档