【问题标题】:PhpMailer error : Message could not be sent.Mailer Error: SMTP connect() failedPhpMailer 错误:无法发送邮件。Mailer 错误:SMTP 连接()失败
【发布时间】:2016-08-14 21:31:48
【问题描述】:

我在 google 和这个网站上搜索,但无法修复这个 phpMailer 错误,这就是我需要你帮助的原因。

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

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

PhpMailer 代码

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 connect() 失败。 github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 无法发送消息。Mailer 错误:SMTP 连接()失败。 github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

更新:

来自我的服务器的当前错误:

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

【问题讨论】:

  • 试试reading the link 然后告诉我们它告诉你什么具体错误
  • 好吧,我正在阅读。
  • @RiggsFolly,我收到此错误: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
  • 奇怪的是,这意味着您连接邮件服务器的尝试被拒绝了。您知道,您对出站邮件的访问可能受到 ISP 防火墙的限制,正如故障排除指南和该问题的所有其他副本所说的那样。
  • 以后,在您的问题中添加任何额外信息。您可以根据需要多次编辑它。没有人可以在评论中看到这样的内容

标签: php phpmailer


【解决方案1】:

为 SMTP 尝试降低您的 gmail 安全性!

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

并添加 debuginfo 属性以查看更多错误。

$mail->SMTPDebug = 1;

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

希望对你有所帮助;)

【讨论】:

    【解决方案2】:

    第 1 步:进入 Gmail 设置并启用 IMAP。 Step2:清除浏览器缓存并检查。

    如果问题仍然存在,请使用“设置”标签降低您的 Gmail 安全性。 Gmail Security alert will be like this

    【讨论】:

      【解决方案3】:

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

      $mail->SMTPDebug = 3;

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

      【讨论】:

        猜你喜欢
        • 2018-01-18
        • 1970-01-01
        • 1970-01-01
        • 2016-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-19
        相关资源
        最近更新 更多