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

我已经build立了一个Web服务器来使用SMTP服务器来发送电子邮件。

以下是我尝试发送testing电子邮件时生成的一部分日志条目:

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. 

可能是什么问题呢?

编辑:下面是WordPress的WP邮件SMTP插件生成的完整日志。 (我已经用example.comreplace了真正的域名来保护隐私)。

 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. 

由于您使用的WP邮件SMTP插件,您的最佳起点将在这里: http : //callum-macdonald.com/code/wp-mail-smtp 。 现在这就是开发者所说的:

无法连接到主机

如果您看到“无法连接到服务器”的错误,该插件正在工作,PHP无法连接到服务器。 看看整个错误信息并从那里调查。 检查你的php.ini设置fopen()权限,检查你的SMTP主机是否正确,或联系你的服务器pipe理员。

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

既然你没有发布你的插件设置,并提供不同的configuration可能性,这里有一些要帮助你。

  • debugging错误说:“SMTP错误:无法validation。”,所以检查并确保您的validation信息是正确的。
  • 该插件兼有php-mailer和SMTP邮件选项,所以试试看看。 对于php-mailer,检查上面提到的必要的php设置。
  • 至于SMTP问题,你可以使用远程Web服务器运行一个smtp会话,并提供你在插件中使用的数据,看看是否有效。 这里是: 如何检查与手动telnet会话的SMTP连接。

猜测 – 你已经configuration你的SMTP客户端需要安全连接(因此STARTTLS请求到服务器),但SMTP服务器不明白它,所以客户端决定它不能连接?

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