PHPMailer可以确定SMTP失败的确切原因吗?

时间:2018-01-31 21:22:09

标签: php smtp phpmailer

我目前正在编写一个帮助用户配置SMTP发送的工具,并且正在使用PHPMailer来实现这一目标。目前我通知用户SMTP操作是否成功,我想更具体。

在源代码中,它说:

// The reason for failing to send will be in $mail->ErrorInfo

但是,此属性的内容不是非常具体。例如,对于失败的auth和无法访问的服务器,我得到相同的错误:

  

SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

但是,如果我使用PHPMailer的调试级别2深入了解SMTP日志,我会获得更多有用的信息。对于失败的身份验证:

2018-01-31 19:37:12 SERVER -> CLIENT: 535 Incorrect authentication data
2018-01-31 19:37:12 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2018-01-31 19:37:12 SMTP Error: Could not authenticate.

对于无法访问的服务器:

2018-01-31 21:12:34 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)

因此,看起来这些信息可用,但它可能因不同的邮件服务器类型而异。在PHPMailer中有没有解析这个?我喜欢可以测试的可靠原因代码,而不是在日志中搜索可能与每个服务器不匹配的字符串。

我希望还有其他类型的故障,例如配置错误的证书。

0 个答案:

没有答案