发布日期:2018-03-26
PHPMailer :SMTP Error: Could not connect to SMTP host.+ 查看更多
PHPMailer :SMTP Error: Could not connect to SMTP host.
+ 查看更多
发布日期:2018-03-10 14:54
分类:PHP
浏览次数:224
如下:
我在一些项目中使用了PHPMailer但是现在我有点不知所措。错误是这样显示的:
我在一些项目中使用了PHPMailer但是现在我有点不知所措。错误是这样显示的:
SMTP Error: Could not connect to SMTP host.
(SMTP错误,不能链接大SMTP主机)我用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
哪里有错误?
回答:
我认为因为在PHP中缺乏SSL的支持所以才出错的。
所以我启用extension=php_openssl.dll ,设置$mail->SMTPDebug = 1;
并且对这个方案进行提示。
所以我启用extension=php_openssl.dll ,设置$mail->SMTPDebug = 1;
并且对这个方案进行提示。
更新于2017
$mail->SMTPDebug = 2;参考链接:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output
$mail->SMTPDebug = 2;参考链接:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output