dragon188199 2017-03-30 14:33
浏览 177

PHPMailer smtp连接缺失220

I have a problem connecting to SMTP-Server via PHPMailer.

<?php
$mail = new PHPMailer();
$mail->isSMTP();

$mail->SMTPDebug = true;

$mail->Host = "ip.ip.ip.ip";
$mail->Port = "25";
$mail->Helo = "";
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = "";
$mail->SMTPAuth = false;
$mail->Timeout = 10;

$mail->From = "sender@example.com";
$mail->FromName = "Sender Name";

$mail->addAddress("receiver@example.com");

$mail->isHTML(true);
$mail->Subject = "Test";
$mail->Body = "<h1>Test</h1>";


if(!$mail->Send()) {
    echo $mail->ErrorInfo;
} else {
    echo "Mail sent...";
}

I figured out the main problem: After successfully connect the server is NOT sending a "220 announcement" directly. It is sending nothing but waiting for a EHLO. After any client input the server sends a "220 announcement"! I tested it with telnet.

I newer saw it before and i don't know if it respects the rfc.

The 220 AFTER the EHLO makes PHPMailer completely crashing. Any following communication is "misunderstood". I saw that PHPMailer is waiting for a 220 announcement after connecting. But this fails because the server is not sending anything. When the timeout is reached the client sends a EHLO. After that it receives a 220 but the following communication fails.

Here is the full communication output:

2017-03-30 13:38:48     Connection: opening to ip.ip.ip.ip:587, timeout=10, options=array (
                                          )
2017-03-30 13:38:48     Connection: opened
2017-03-30 13:38:58     SMTP -> get_lines(): $data is ""
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  ""
2017-03-30 13:38:58     SMTP -> get_lines(): timed-out (10 sec)
2017-03-30 13:38:58     SERVER -> CLIENT:
2017-03-30 13:38:58     CLIENT -> SERVER: EHLO conweb1.example.de
2017-03-30 13:38:58     SMTP -> get_lines(): $data is ""
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "220 EX-02.example.loc Microsoft ESMTP MAIL Service ready at Thu, 30 Mar 2017 15:38:58 +0200
                                          "
2017-03-30 13:38:58     SERVER -> CLIENT: 220 EX-02.example.loc Microsoft ESMTP MAIL Service ready at Thu, 30 Mar 2017 15:38:58 +0200
2017-03-30 13:38:58     SMTP ERROR: EHLO command failed: 220 EX-02.example.loc Microsoft ESMTP MAIL Service ready at Thu, 30 Mar 2017 15:38:58 +0200
2017-03-30 13:38:58     CLIENT -> SERVER: HELO conweb1.example.de
2017-03-30 13:38:58     SMTP -> get_lines(): $data is ""
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-SIZE 36700160
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-PIPELINING
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-DSN
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          250-DSN
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-ENHANCEDSTATUSCODES
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          250-DSN
                                          250-ENHANCEDSTATUSCODES
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-STARTTLS
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          250-DSN
                                          250-ENHANCEDSTATUSCODES
                                          250-STARTTLS
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-AUTH LOGIN
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          250-DSN
                                          250-ENHANCEDSTATUSCODES
                                          250-STARTTLS
                                          250-AUTH LOGIN
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-8BITMIME
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          250-DSN
                                          250-ENHANCEDSTATUSCODES
                                          250-STARTTLS
                                          250-AUTH LOGIN
                                          250-8BITMIME
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250-BINARYMIME
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $data is "250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          250-DSN
                                          250-ENHANCEDSTATUSCODES
                                          250-STARTTLS
                                          250-AUTH LOGIN
                                          250-8BITMIME
                                          250-BINARYMIME
                                          "
2017-03-30 13:38:58     SMTP -> get_lines(): $str is  "250 CHUNKING
                                          "
2017-03-30 13:38:58     SERVER -> CLIENT: 250-EX-02.example.loc Hello [ip.ip.ip.ip]
                                          250-SIZE 36700160
                                          250-PIPELINING
                                          250-DSN
                                          250-ENHANCEDSTATUSCODES
                                          250-STARTTLS
                                          250-AUTH LOGIN
                                          250-8BITMIME
                                          250-BINARYMIME
                                          250 CHUNKING
2017-03-30 13:38:58     CLIENT -> SERVER: MAIL FROM:<personal@example.com>
2017-03-30 13:39:03     SMTP -> get_lines(): $data is ""
2017-03-30 13:39:03     SMTP -> get_lines(): $str is  "250 EX-02.example.loc Hello [ip.ip.ip.ip]
                                          "
2017-03-30 13:39:03     SERVER -> CLIENT: 250 EX-02.example.loc Hello [ip.ip.ip.ip]
2017-03-30 13:39:03     CLIENT -> SERVER: RCPT TO:<tm@example.com>
2017-03-30 13:39:03     SMTP -> get_lines(): $data is ""
2017-03-30 13:39:03     SMTP -> get_lines(): $str is  "250 2.1.0 Sender OK
                                          "
2017-03-30 13:39:03     SERVER -> CLIENT: 250 2.1.0 Sender OK
2017-03-30 13:39:03     CLIENT -> SERVER: DATA
2017-03-30 13:39:03     SMTP -> get_lines(): $data is ""
2017-03-30 13:39:03     SMTP -> get_lines(): $str is  "250 2.1.5 Recipient OK
                                          "
2017-03-30 13:39:03     SERVER -> CLIENT: 250 2.1.5 Recipient OK
2017-03-30 13:39:03     SMTP ERROR: DATA command failed: 250 2.1.5 Recipient OK
2017-03-30 13:39:03     SMTP Error: data not accepted.
SMTP Error: data not accepted.SMTP server error: DATA command failed Detail: Recipient OK
 SMTP code: 250 Additional SMTP info: 2.1.52017-03-30 13:39:03  CLIENT -> SERVER: QUIT
2017-03-30 13:39:03     SMTP -> get_lines(): $data is ""
2017-03-30 13:39:03     SMTP -> get_lines(): $str is  "354 Start mail input; end with <CRLF>.<CRLF>
2017-03-30 13:39:03     SMTP ERROR: QUIT command failed: 354 Start mail input; end with <CRLF>.<CRLF>
2017-03-30 13:39:03     Connection: closed

The main question is: Is the error caused by a wrong protocol implementation of PHP-Mailer? Or is the SMTP Server misconfigured?

  • 写回答

1条回答 默认 最新

  • duandian4501 2017-03-30 16:41
    关注

    Don't do this:

    $mail->Timeout = 10;
    

    RFC2821 specifies a timeout of 300sec (5 minutes) on the initial greeting, and some servers impose a long delay here (known as a "greet delay") specifically to trap non-conforming clients, usually spambots. PHPMailer respects this exactly with its default Timeout setting of 300 sec. If you shorten it, you're preventing it from waiting for long enough. Does it work if you set it to 300 or leave at its default setting?

    If you say "but I don't want to wait that long during page processing!" - welcome to the world of SMTP - it's not designed for real-time use; use a local mail server relay to remove this delay and let the mail server worry about it.

    评论

报告相同问题?

悬赏问题

  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL