【发布时间】:2017-03-30 14:33:19
【问题描述】:
我通过 PHPMailer 连接到 SMTP 服务器时遇到问题。
<?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...";
}
我发现了主要问题: 成功连接后,服务器不会直接发送“220 公告”。它除了等待 EHLO 什么都没有发送。在任何客户端输入后,服务器都会发送“220 公告”!我用 telnet 测试了一下。
我以前看到过它,我不知道它是否尊重 rfc。
EHLO 之后的 220 使 PHPMailer 完全崩溃。任何以下通信都是“误解”。我看到PHPMailer连接后正在等待220公告。但这失败了,因为服务器没有发送任何东西。当达到超时时,客户端发送一个 EHLO。之后它会收到 220 但以下通信失败。
这是完整的通信输出:
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
主要问题是: 错误是由PHP-Mailer的错误协议实现引起的吗? 还是 SMTP 服务器配置错误?
【问题讨论】:
-
您询问是否可以在 smtp 服务器上执行命令,您可以使用 telnet 测试以验证是否可以执行命令,另一个观察结果似乎数据为空
-
尝试在 $mail->Body 之后添加 $mail->AltBody ="Test"
-
@GuillermoAndresFuentesMoral 数据不是空的!该代码适用于其他 smtp 服务器!我成功地测试了telnet。原因是响应延迟是由开始时的220后期造成的。客户会误解任何以下响应。如您所见,首先由于缺少 220 问候而导致超时。
-
他们可以将服务器配置为在发送问候语之前延迟超过 10 秒(以减少垃圾邮件)。在收到问候语之前发送 helo/ehlo 是违反 rfc 的,但您可能需要等待更长时间。通过 telnet,如果您连接并让它静置,它最终会发送问候语吗?
-
@drew010 不!不是在我发送任何东西之前。但是如果我发送一些东西,它会立即回复 220...
标签: php smtp phpmailer smtpclient