PhpMailer 错误:无法发送消息.邮件程序错误: SMTP 连接() 失败


PhpMailer error : Message could not be sent.Mailer Error: SMTP connect() failed

我搜索谷歌和这个网站,无法修复这个phpMailer错误,这就是为什么我需要你的帮助。

我使用以下phpMailer代码发送电子邮件,但它一直向我显示错误消息:

无法发送消息。邮件程序错误: SMTP 连接() 失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

PhpMailer Code

require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();                                     
$mail->Host =  gethostbyname("smtp.gmail.com");  
$mail->SMTPAuth = true;                          
$mail->Username = 'hello@gmail.com';        
$mail->Password = 'password';                 
$mail->SMTPSecure = 'ssl';                       
$mail->Port = 465;                               
$mail->isHTML(true);   
$mail->Priority = 1; 
$to = 'to@gmail.com';
$mail->setFrom('support@site.com', 'Sitename');
// Send Email tto user ####################################
$mail->addAddress('some@gmail.com', 'Shibbir Ahmed');
// send email to admin #####################################
$mail->addReplyTo('some@gmail.com', 'Information');
$mail->Subject = 'Test Subject';
$get_templae = mysqli_query($conn, "SELECT * FROM email_template WHERE t_id = '8' ");
$get_restult =  mysqli_fetch_array($get_templae);
$template =  $get_restult['t_content'];
$mail->Body    = $template;
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

你能告诉我在这个代码中做错了什么吗?

我收到此错误:

2016-04-21 15:19:51 SMTP 错误: 无法连接到服务器: 连接被拒绝 (111) 2016-04-21 15:19:51 SMTP 连接() 失败。 github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 无法发送消息。邮件程序错误: SMTP 连接() 失败。github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

更新:

我的服务器当前错误:

2016-04-21 18:06:01 SMTP 错误: 无法连接到服务器: 连接被拒绝 (111) 2016-04-21 18:06:01 SMTP 连接() 失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 布尔(假)

尝试降低您的Gmail安全性,用于SMTP!

链接: https://www.google.com/settings/security/lesssecureapps

并添加 de debuginfo 属性以查看更多问题所在。

$mail->SMTPDebug = 1;

您可以将值更改为 1 2 3 或 4 以进入过滤表单 DebugInfo。

希望这对您有所帮助;)

调试 PHPMailer 错误的最佳方法是取消注释

$mail->SMTPDebug = 3;

它将为您提供所发生事件的详细日志。从身份验证一直到请求成功或失败的位置

步骤1:转到Gmail设置并启用IMAP。步骤2:清除浏览器缓存并检查它。

如果问题仍然存在,请使用"设置"标签降低Gmail的安全性。Gmail安全警报将是这样的