我已经在几个项目中使用了PHPMailer,但现在我被困住了。它给了我一个错误:
SMTP错误:无法连接到SMTP主机.
我试过发送雷鸟的电子邮件,这是有效的!但不是通过PHPMailer ..。以下是雷鸟的设置:
服务器名称: mail.exampleserver.com
端口: 587
用户名: user@exampleserver.com
安全认证:没有
连接安全性: STARTTLS
在我最后一个使用PHPMailer的项目中,我将它们与服务器进行了比较,它们是:
服务器名称: mail.exampleserver2.com
端口: 465
用户名:@exampleserver2.com
安全认证:没有
连接安全性:SSL/
我的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我哪里错了?
发布于 2016-04-04 14:32:56
由于这个问题在google中显示得很高,我想在这里分享我的解决方案,因为PHP刚刚升级到版本5.6 (它具有更严格的SSL行为)。
PHPMailer wiki有一个关于这一点的章节:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#php-56-certificate-verification-failure
建议的解决方法包括以下代码:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);这应该适用于PHPMailer 5.2.10 (及以上)。
注:很明显,正如wiki中所建议的,这应该是一个临时的解决方案!
正确的修复方法是用一个好的证书替换无效的、配置错误的或自签名的证书。。
发布于 2011-04-18 22:57:45
在我的例子中,是PHP缺乏SSL支持导致了这个错误。
所以我启用了extension=php_openssl.dll
$mail->SMTPDebug = 1;也暗示了这个解决方案。
更新2017年
$mail->SMTPDebug = 2;,见:https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output
发布于 2010-08-13 15:41:13
你的问题很可能是
连接安全性: STARTTLS连接安全性: SSL/TLS
这是两个不同的协议,你是否使用了正确的协议,无论你在雷鸟中使用的是什么,都需要使用。
尝试设置变量:
// if you're using SSL
$mail->SMTPSecure = 'ssl';
// OR use TLS
$mail->SMTPSecure = 'tls';https://stackoverflow.com/questions/3477766
复制相似问题