SMTP 服务器已准备就绪,但出现“无法连接”错误

SMTP 服务器已准备就绪,但出现“无法连接”错误

我已经设置了一个 Web 服务器以使用 SMTP 服务器发送电子邮件。

这是我尝试发送测试电子邮件时生成的部分日志条目:

2016-02-03 10:20:01 CLIENT -> SERVER: STARTTLS
2016-02-03 10:20:01 SMTP -> get_lines(): $data was ""
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "220 2.0.0 SMTP server ready
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "220 2.0.0 SMTP server ready
                                      "
2016-02-03 10:20:01 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2016-02-03 10:20:01 SMTP Error: Could not connect to SMTP host.
2016-02-03 10:20:01 CLIENT -> SERVER: QUIT
2016-02-03 10:20:01 SMTP -> get_lines(): $data was ""
2016-02-03 10:20:01 SMTP -> get_lines(): $str is ""
2016-02-03 10:20:01 SMTP -> get_lines(): $data is ""
2016-02-03 10:20:01 SERVER -> CLIENT:
2016-02-03 10:20:01 SMTP ERROR: QUIT command failed:
2016-02-03 10:20:01 Connection: closed
2016-02-03 10:20:01 SMTP Error: Could not connect to SMTP host.

可能是什么问题呢?

编辑:以下是生成的完整日志WP 邮件 SMTPWordPress 中的插件。 (为了保护隐私,我已将真实域名替换为 example.com)。

Test Message Sent

The result was:
bool(false)


The full debugging output is shown below:
object(PHPMailer)#752 (73) {
  ["Version"]=>
  string(6) "5.2.10"
  ["Priority"]=>
  int(3)
  ["CharSet"]=>
  string(5) "UTF-8"
  ["ContentType"]=>
  string(10) "text/plain"
  ["Encoding"]=>
  string(4) "8bit"
  ["ErrorInfo"]=>
  string(43) "SMTP Error: Could not connect to SMTP host."
  ["From"]=>
  string(17) "[email protected]"
  ["FromName"]=>
  string(14) "Administration"
  ["Sender"]=>
  string(0) ""
  ["ReturnPath"]=>
  string(0) ""
  ["Subject"]=>
  string(45) "WP Mail SMTP: Test mail to [email protected]"
  ["Body"]=>
  string(68) "This is a test email generated by the WP Mail SMTP WordPress plugin."
  ["AltBody"]=>
  string(0) ""
  ["Ical"]=>
  string(0) ""
  ["MIMEBody":protected]=>
  string(69) "This is a test email generated by the WP Mail SMTP WordPress plugin.
"
  ["MIMEHeader":protected]=>
  string(392) "Date: Wed, 3 Feb 2016 10:20:01 +0000
To: [email protected]
From: Administration 
Subject: WP Mail SMTP: Test mail to [email protected]
Message-ID: 
X-Priority: 3
X-Mailer: PHPMailer 5.2.10 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

"
  ["mailHeader":protected]=>
  string(0) ""
  ["WordWrap"]=>
  int(0)
  ["Mailer"]=>
  string(4) "smtp"
  ["Sendmail"]=>
  string(18) "/usr/sbin/sendmail"
  ["UseSendmailOptions"]=>
  bool(true)
  ["PluginDir"]=>
  string(0) ""
  ["ConfirmReadingTo"]=>
  string(0) ""
  ["Hostname"]=>
  string(14) "www.example.com"
  ["MessageID"]=>
  string(0) ""
  ["MessageDate"]=>
  string(30) "Wed, 3 Feb 2016 10:20:01 +0000"
  ["Host"]=>
  string(12) "192.168.1.23"
  ["Port"]=>
  string(2) "25"
  ["Helo"]=>
  string(0) ""
  ["SMTPSecure"]=>
  string(0) ""
  ["SMTPAutoTLS"]=>
  bool(true)
  ["SMTPAuth"]=>
  bool(true)
  ["SMTPOptions"]=>
  array(0) {
  }
  ["Username"]=>
  string(9) "workflow"
  ["Password"]=>
  string(10) "example"
  ["AuthType"]=>
  string(0) ""
  ["Realm"]=>
  string(0) ""
  ["Workstation"]=>
  string(0) ""
  ["Timeout"]=>
  int(300)
  ["SMTPDebug"]=>
  bool(true)
  ["Debugoutput"]=>
  string(4) "echo"
  ["SMTPKeepAlive"]=>
  bool(false)
  ["SingleTo"]=>
  bool(false)
  ["SingleToArray"]=>
  array(0) {
  }
  ["do_verp"]=>
  bool(false)
  ["AllowEmpty"]=>
  bool(false)
  ["LE"]=>
  string(1) "
"
  ["DKIM_selector"]=>
  string(0) ""
  ["DKIM_identity"]=>
  string(0) ""
  ["DKIM_passphrase"]=>
  string(0) ""
  ["DKIM_domain"]=>
  string(0) ""
  ["DKIM_private"]=>
  string(0) ""
  ["action_function"]=>
  string(0) ""
  ["XMailer"]=>
  string(0) ""
  ["smtp":protected]=>
  object(SMTP)#643 (13) {
    ["Version"]=>
    string(6) "5.2.10"
    ["SMTP_PORT"]=>
    int(25)
    ["CRLF"]=>
    string(2) "
"
    ["do_debug"]=>
    bool(true)
    ["Debugoutput"]=>
    string(4) "echo"
    ["do_verp"]=>
    bool(false)
    ["Timeout"]=>
    int(300)
    ["Timelimit"]=>
    int(300)
    ["smtp_conn":protected]=>
    NULL
    ["error":protected]=>
    array(4) {
      ["error"]=>
      string(0) ""
      ["detail"]=>
      string(0) ""
      ["smtp_code"]=>
      string(0) ""
      ["smtp_code_ex"]=>
      string(0) ""
    }
    ["helo_rply":protected]=>
    NULL
    ["server_caps":protected]=>
    NULL
    ["last_reply":protected]=>
    string(0) ""
  }
  ["to":protected]=>
  array(1) {
    [0]=>
    array(2) {
      [0]=>
      string(18) "[email protected]"
      [1]=>
      string(0) ""
    }
  }
  ["cc":protected]=>
  array(0) {
  }
  ["bcc":protected]=>
  array(0) {
  }
  ["ReplyTo":protected]=>
  array(0) {
  }
  ["all_recipients":protected]=>
  array(1) {
    ["[email protected]"]=>
    bool(true)
  }
  ["attachment":protected]=>
  array(0) {
  }
  ["CustomHeader":protected]=>
  array(0) {
  }
  ["lastMessageID":protected]=>
  string(49) ""
  ["message_type":protected]=>
  string(5) "plain"
  ["boundary":protected]=>
  array(3) {
    [1]=>
    string(35) "b1_f87804706227482a31d3248b0776feb6"
    [2]=>
    string(35) "b2_f87804706227482a31d3248b0776feb6"
    [3]=>
    string(35) "b3_f87804706227482a31d3248b0776feb6"
  }
  ["language":protected]=>
  array(19) {
    ["authenticate"]=>
    string(35) "SMTP Error: Could not authenticate."
    ["connect_host"]=>
    string(43) "SMTP Error: Could not connect to SMTP host."
    ["data_not_accepted"]=>
    string(30) "SMTP Error: data not accepted."
    ["empty_message"]=>
    string(18) "Message body empty"
    ["encoding"]=>
    string(18) "Unknown encoding: "
    ["execute"]=>
    string(19) "Could not execute: "
    ["file_access"]=>
    string(23) "Could not access file: "
    ["file_open"]=>
    string(33) "File Error: Could not open file: "
    ["from_failed"]=>
    string(35) "The following From address failed: "
    ["instantiate"]=>
    string(36) "Could not instantiate mail function."
    ["invalid_address"]=>
    string(15) "Invalid address"
    ["mailer_not_supported"]=>
    string(25) " mailer is not supported."
    ["provide_address"]=>
    string(54) "You must provide at least one recipient email address."
    ["recipients_failed"]=>
    string(45) "SMTP Error: The following recipients failed: "
    ["signing"]=>
    string(15) "Signing Error: "
    ["smtp_connect_failed"]=>
    string(22) "SMTP connect() failed."
    ["smtp_error"]=>
    string(19) "SMTP server error: "
    ["variable_set"]=>
    string(30) "Cannot set or reset variable: "
    ["extension_missing"]=>
    string(19) "Extension missing: "
  }
  ["error_count":protected]=>
  int(2)
  ["sign_cert_file":protected]=>
  string(0) ""
  ["sign_key_file":protected]=>
  string(0) ""
  ["sign_extracerts_file":protected]=>
  string(0) ""
  ["sign_key_pass":protected]=>
  string(0) ""
  ["exceptions":protected]=>
  bool(true)
  ["uniqueid":protected]=>
  string(32) "f87804706227482a31d3248b0776feb6"
}


The SMTP debugging output is shown below:
2016-02-03 10:20:01 Connection: opening to 192.168.1.23:25, timeout=300, options=array (
                                      )
2016-02-03 10:20:01 Connection: opened
2016-02-03 10:20:01 SMTP -> get_lines(): $data was ""
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "220 AEADTWMAVSM002.example.com Microsoft ESMTP MAIL Service ready at Wed, 3 Feb 2016 14:20:01 +0400
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "220 AEADTWMAVSM002.example.com Microsoft ESMTP MAIL Service ready at Wed, 3 Feb 2016 14:20:01 +0400
                                      "
2016-02-03 10:20:01 SERVER -> CLIENT: 220 AEADTWMAVSM002.example.com Microsoft ESMTP MAIL Service ready at Wed, 3 Feb 2016 14:20:01 +0400
2016-02-03 10:20:01 CLIENT -> SERVER: EHLO www.example.com
2016-02-03 10:20:01 SMTP -> get_lines(): $data was ""
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-SIZE 10485760
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-PIPELINING
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-DSN
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-STARTTLS
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-AUTH
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-8BITMIME
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      250-8BITMIME
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      250-8BITMIME
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250-BINARYMIME
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      250-8BITMIME
                                      250-BINARYMIME
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data was "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      250-8BITMIME
                                      250-BINARYMIME
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "250 CHUNKING
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      250-8BITMIME
                                      250-BINARYMIME
                                      250 CHUNKING
                                      "
2016-02-03 10:20:01 SERVER -> CLIENT: 250-AEADTWMAVSM002.example.com Hello [192.168.3.51]
                                      250-SIZE 10485760
                                      250-PIPELINING
                                      250-DSN
                                      250-ENHANCEDSTATUSCODES
                                      250-STARTTLS
                                      250-AUTH
                                      250-8BITMIME
                                      250-BINARYMIME
                                      250 CHUNKING
2016-02-03 10:20:01 CLIENT -> SERVER: STARTTLS
2016-02-03 10:20:01 SMTP -> get_lines(): $data was ""
2016-02-03 10:20:01 SMTP -> get_lines(): $str is "220 2.0.0 SMTP server ready
                                      "
2016-02-03 10:20:01 SMTP -> get_lines(): $data is "220 2.0.0 SMTP server ready
                                      "
2016-02-03 10:20:01 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2016-02-03 10:20:01 SMTP Error: Could not connect to SMTP host.
2016-02-03 10:20:01 CLIENT -> SERVER: QUIT
2016-02-03 10:20:01 SMTP -> get_lines(): $data was ""
2016-02-03 10:20:01 SMTP -> get_lines(): $str is ""
2016-02-03 10:20:01 SMTP -> get_lines(): $data is ""
2016-02-03 10:20:01 SERVER -> CLIENT:
2016-02-03 10:20:01 SMTP ERROR: QUIT command failed:
2016-02-03 10:20:01 Connection: closed
2016-02-03 10:20:01 SMTP Error: Could not connect to SMTP host.

答案1

由于您正在使用 WP Mail SMTP 插件,因此最好的起点是这里:http://callum-macdonald.com/code/wp-mail-smtp。下面是开发人员的说法:

无法连接到主机

如果您看到“无法连接到服务器”之类的错误,则表示插件正常运行,PHP 无法连接到服务器。查看整个错误消息并从那里进行调查。检查您的 php.ini 设置中的 fopen() 权限,检查您的 SMTP 主机是否正确,或者联系您的服务器管理员。

如果您的错误是“无法连接到主机”,请到其他地方寻求支持,请不要在这里寻求支持。这些问题之前已经被问过很多次了,请搜索历史记录。插件可以正常工作,问题出在其他地方。

由于您尚未发布插件的设置,并且它提供了不同的配置可能性,这里有一些要点可以帮助您。

  • 调试错误显示:“SMTP 错误:无法验证。”,因此请检查并确保您的验证信息正确无误。
  • 该插件提供 php-mailer 和 SMTP 邮件选项,因此请尝试两者并查看。对于 php-mailer,请检查上述所需的 php 设置。
  • 至于 SMTP 问题,您可以使用来自 Web 服务器的 telent 运行 smtp 会话,并在插件中提供您正在使用的数据,以查看它是否有效。以下是:如何使用手动 telnet 会话检查 SMTP 连接。

答案2

猜测一下——您已将 SMTP 客户端配置为需要安全连接(因此向服务器发出 STARTTLS 请求),但 SMTP 服务器不理解它,所以客户端决定无法连接?

(您也可能尝试连接端口 25 而不是更常用于 TLS SMTP 的端口 587。如果连接到端口 25,则必须在发出“STARTTLS”命令之前进行服务器握手)。

相关内容