SMTP connect() failed

时间:2017-09-15 作者:IamDade89

我们正在尝试设置SMTP功能,但在测试电子邮件中不断出现错误。我们甚至尝试了WP Mail SMTP和Easy WP SMTP。在与WPEngine的主机交谈后,我们没有发现任何问题,因为他们确实使用OpenSSL,并告诉我们使用端口2525,因为我们使用Outlook。我们的IT部门还表示,该端口应该工作正常,不会被Outlook阻止。我甚至使用了premierdisability com的另一个SMTP主机名。邮政保护见解com。然而,这一个给出了相同的错误,但表示连接超时,而不是网络无法访问。

我能想到的唯一选项是编辑/交换类phpmailer。php和类smtp。旧版本的php文件。但是Easy WP SMTP表示它应该与我们的WP设置兼容(WP v4.8,PHP v5.6)。你认为这是一个很好的选择,或者知道还有什么可以尝试的吗?

  object(PHPMailer)#1882 (76) {
  ["Version"]=>
  string(6) "5.2.22"
  ["Priority"]=>
  NULL
  ["CharSet"]=>
  string(5) "UTF-8"
  ["ContentType"]=>
  string(10) "text/plain"
  ["Encoding"]=>
  string(4) "7bit"
  ["ErrorInfo"]=>
  string(82) "SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting"
  ["From"]=>
  string(34) "[email protected]"
  ["FromName"]=>
  string(27) "Premier Disability Services"
  ["Sender"]=>
  string(34) "[email protected]"
  ["ReturnPath"]=>
  string(0) ""
  ["Subject"]=>
  string(56) "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(405) "Date: Fri, 15 Sep 2017 18:16:49 +0000
To: [email protected]
From: Premier Disability Services 
Subject: WP Mail SMTP: Test mail to [email protected]
Message-ID: <[email protected]>
X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8

"
  ["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(0) ""
  ["MessageID"]=>
  string(0) ""
  ["MessageDate"]=>
  string(31) "Fri, 15 Sep 2017 18:16:49 +0000"
  ["Host"]=>
  string(18) "smtp.office365.com"
  ["Port"]=>
  string(4) "2525"
  ["Helo"]=>
  string(0) ""
  ["SMTPSecure"]=>
  string(3) "tls"
  ["SMTPAutoTLS"]=>
  bool(false)
  ["SMTPAuth"]=>
  bool(true)
  ["SMTPOptions"]=>
  array(0) {
  }
  ["Username"]=>
  string(34) "[email protected]"
  ["Password"]=>
  string(8) "*******"
  ["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) ""
  ["DKIM_private_string"]=>
  string(0) ""
  ["action_function"]=>
  string(0) ""
  ["XMailer"]=>
  string(0) ""
  ["smtp":protected]=>
  object(SMTP)#1886 (14) {
    ["Version"]=>
    string(6) "5.2.22"
    ["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_transaction_id_patterns":protected]=>
    array(3) {
      ["exim"]=>
      string(21) "/[0-9]{3} OK id=(.*)/"
      ["sendmail"]=>
      string(29) "/[0-9]{3} 2.0.0 (.*) Message/"
      ["postfix"]=>
      string(35) "/[0-9]{3} 2.0.0 Ok: queued as (.*)/"
    }
    ["smtp_conn":protected]=>
    bool(false)
    ["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(29) "[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)
  }
  ["RecipientsQueue":protected]=>
  array(0) {
  }
  ["ReplyToQueue":protected]=>
  array(0) {
  }
  ["attachment":protected]=>
  array(0) {
  }
  ["CustomHeader":protected]=>
  array(0) {
  }
  ["lastMessageID":protected]=>
  string(56) "<[email protected]>"
  ["message_type":protected]=>
  string(5) "plain"
  ["boundary":protected]=>
  array(3) {
    [1]=>
    string(35) "b1_2b81fcc2a1a7b45ecfed265c6f74ed17"
    [2]=>
    string(35) "b2_2b81fcc2a1a7b45ecfed265c6f74ed17"
    [3]=>
    string(35) "b3_2b81fcc2a1a7b45ecfed265c6f74ed17"
  }
  ["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(17) "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) "2b81fcc2a1a7b45ecfed265c6f74ed17"
}
The SMTP debugging output is shown below:

2017-09-15 18:16:49 Connection: opening to smtp.office365.com:2525, timeout=300, options=array (
                                      )
2017-09-15 18:17:59 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to smtp.office365.com:2525 (Network is unreachable)
2017-09-15 18:17:59 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
2017-09-15 18:17:59 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

3 个回复
SO网友:Loudsy

我昨天才发现我们有这个问题。今天早上已成功安装mailgun。每月不超过10000封电子邮件是免费的。

SO网友:Daniel Maier

如果您的IT部门允许您的服务器IP使用端口2525进行连接,请仔细检查。我也有WP引擎上的站点,并使用SMTP代码连接到我们的内部邮件服务器并从那里发送电子邮件。然而,我不得不将我们的WP引擎服务器IP列入防火墙的白名单,以允许通过端口2525的流量。

SO网友:matthewd

这个问题有点老了,但我想和现在有同样问题的人分享我的经验。

我的设置是:PHP 7.4, WordPress 5.7.2, WP Mail SMTP 2.8.0

我想使用自定义的外部SMTP服务器。不要问为什么。这很复杂。

我已经按照邮件/托管提供商的指示设置了所有内容,但一直得到"SMTP connect() failed""SMTP Error: Could not authenticate" 错误。

经过一点挖掘和一些支持事务后,更改默认值AuthType 属于PHPMailer 修复了它。它默认为"CRAM-MD5" 而且不起作用。将其切换到"PLAIN" 已修复问题。由于一切都是加密的,我决定"PLAIN" 数据不应该是问题。这是我的主机提供商的问题,但是我鼓励任何有相同问题的人尝试AuthType

在中执行以下操作functions.php 使修复持久化,以便我可以无需担心地更新WordPress及其插件:

add_filter( \'wp_mail_smtp_custom_options\', function( $phpmailer ) {
    $phpmailer->AuthType = \'PLAIN\';
    
    return $phpmailer;
} );
希望这对别人有帮助!

结束

相关推荐

Sending all emails using SMTP

我两个都试过了Configure SMTP 和WP Mail SMTP 通过我的donotreply Google Apps电子邮件地址发送所有域电子邮件,但这两个插件都不起作用。尝试通过其中一个发送测试电子邮件会导致错误SMTP -> ERROR: Failed to connect to server: Network is unreachable (101). 我正确输入了信息(smtp.gmail.com,端口465或587[两者都尝试过]、SSL[也尝试了TLS]),但它无法连接。我是否需