我被困了 . 它给了我错误:
SMTP Error: Could not connect to SMTP host.
我尝试过从Thunderbird发送电子邮件,但它确实有效!但不是通过PHPMailer ......以下是Thunderbird的设置:
Server name: mail.exampleserver.com Port: 587 Username: user@exampleserver.com Secure Authentication: No Connection Security: STARTTLS
我在上一个使用PHPMailer的项目中将这些与服务器进行了比较,它们是:
Server name: mail.exampleserver2.com Port: 465 Username: user@exampleserver2.com Secure Authentication: No Connection Security: SSL/TLS
我的PHP代码是:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = SMTP_HOST; // SMTP servers
$mail->Port = SMTP_PORT; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASSWORD; // SMTP password
$mail->From = MAIL_SYSTEM;
$mail->FromName = MAIL_SYSTEM_NAME;
$mail->AddAddress($aSecuredGetRequest['email']);
$mail->IsHTML(true); // send as HTML
哪里错了?
9 回答
mail.exampleserver.com存在吗??? ,如果没有尝试以下代码(你必须有Gmail帐户)
你的问题很可能就是这个问题
连接安全性:STARTTLS连接安全性:SSL / TLS
这些是两种不同的协议,你使用正确的协议,无论你在Thunderbird中使用什么,都需要使用 .
尝试设置变量:
我有一个类似的问题 . 我安装了PHPMailer版本1.72,它不准备管理SSL连接 . 升级到上一版本解决了这个问题 .
由于这是一个流行的错误,请查看PHPMailer Wiki上的故障排除 .
这也适合我
我遇到了类似的问题,并且发现
php.ini
中的openssl.cafile
配置指令需要设置为允许验证安全对等体 . 您只需将其设置为证书颁发机构文件的位置,就像您可以在http://curl.haxx.se/docs/caextract.html获得的那样 .从PHP 5.6开始,这个指令是新的,所以当从PHP 5.5升级时,这让我措手不及 .
我有同样的问题,因为PHPMailer意识到服务器支持STARTTLS所以它试图自动升级连接到加密连接 . 我的邮件服务器与我网络中的Web服务器在同一子网上,这完全在我们的域防火墙后面,所以我不太担心使用加密(加上生成的电子邮件不包含敏感数据) .
所以我要做的就是在class.phpmailer.php文件中将SMTPAutoTLS更改为false .
在我的情况下,PHP中缺少SSL支持,这给出了这个错误 .
所以我启用 extension=php_openssl.dll
$mail->SMTPDebug = 1;
也暗示了这个解决方案 .Update 2017
$mail->SMTPDebug = 2;
,见:https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output由于这个问题在谷歌中显得很高,我想在这里分享我的解决方案,其中PHP刚刚升级到5.6版(具有更严格的SSL行为) .
PHPMailer维基有一个关于此的部分:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#php-56-certificate-verification-failure
建议的解决方法包括以下代码:
这适用于PHPMailer 5.2.10(及以上版本) .
Note: 显然,也就是那个wiki中的建议,这应该是一个临时的解决方案!
以下代码为我工作: