有时在本地主机的gmail端口465或587上,PHPMailer无法正常工作 [英] PHPMailer do not work properly sometimes on gmail port 465 or 587 on localhost

查看:317
本文介绍了有时在本地主机的gmail端口465或587上,PHPMailer无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 LOCALHOST 上的最新版本的 PHPMailer 6.0.2 和Gmail SMTP端口[465上的 SSL TLS 587 ].它运作良好,但不稳定或无法正常运行,这很奇怪,而OpenConfig扩展在PHP Config/PHP.ini文件中也处于活动状态.

I am using the latest version of PHPMailer 6.0.2 on LOCALHOST with Gmail SMTP Ports [ SSL on 465 and TLS 587 ]. It works well but not stable or works properly, very strange while OpenSSL Extension is also active in PHP Config /PHP.ini file.

有时会在465或587端口上返回错误" SMTP错误:无法连接到SMTP主机".

It returns the error " SMTP Error: Could not connect to SMTP host ", sometimes on 465 or 587 port.

现在是587.

这是端口587上的确切错误;

2017-12-05 13:00:26 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
2017-12-05 13:00:26 Connection: opened
2017-12-05 13:00:26 SMTP INBOUND: "220 smtp.gmail.com ESMTP f3sm245851pgt.15 - gsmtp"
2017-12-05 13:00:26 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP f3sm245851pgt.15 - gsmtp
2017-12-05 13:00:26 CLIENT -> SERVER: EHLO localhost
2017-12-05 13:00:27 SMTP INBOUND: "250-smtp.gmail.com at your service, [110.36.136.72]"
2017-12-05 13:00:27 SMTP INBOUND: "250-SIZE 35882577"
2017-12-05 13:00:27 SMTP INBOUND: "250-8BITMIME"
2017-12-05 13:00:27 SMTP INBOUND: "250-STARTTLS"
2017-12-05 13:00:27 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2017-12-05 13:00:27 SMTP INBOUND: "250-PIPELINING"
2017-12-05 13:00:27 SMTP INBOUND: "250-CHUNKING"
2017-12-05 13:00:27 SMTP INBOUND: "250 SMTPUTF8"
2017-12-05 13:00:27 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [110.36.136.72]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2017-12-05 13:00:27 CLIENT -> SERVER: STARTTLS
2017-12-05 13:00:27 SMTP INBOUND: ""
2017-12-05 13:00:27 SERVER -> CLIENT: 
2017-12-05 13:00:27 SMTP ERROR: STARTTLS command failed: 
SMTP Error: Could not connect to SMTP host.
2017-12-05 13:00:27 SMTP NOTICE: EOF caught while checking if connected
2017-12-05 13:00:27 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting     
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

此处是相关代码:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\OAuth;
use League\OAuth2\Client\Provider\Google;

require '../../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 4;

$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;

$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->SMTPAutoTLS = false;

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

$mail->Username = $from_address;
$mail->Password = $from_password;
$mail->SetLanguage("tr", "phpmailer/language");
$mail->CharSet = "utf-8";
$mail->Encoding = "base64";
$mail->SetFrom($from_address, $from_name);

foreach ($to_email_list as $to) {
    $mail->AddAddress($to);
}

$mail->AddReplyTo($from_address, $from_name);
$mail->Subject = $email_subject;

//Creating Email Body
$message = "<html>\n";
$message .= "<body>\n";
$message .= '<p>Greetings,</p>';
$message .= '<p>' . $email_message . '</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$mail->isHTML(true);
$mail->MsgHTML($message);

if(!$mail->Send()) {
    echo "On Port: " . $from_smtp_port . " </br> Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!  on Port " . $from_smtp_port . "</br>";

   foreach($to_email_list as $list){
        echo $list . "</br>";
    }

}

推荐答案

最后,我在问题排查指南.

我建议面临相同问题的其他用户;请在疑难解答指南中仔细查看以下几点; -机会性TLS - PHP 5.6证书验证失败 - cURL错误60

I recommend to other users who are facing the same issue; please see following Points carefully on troubleshooting guide; - Opportunistic TLS - PHP 5.6 certificate verification failure - cURL error 60

我的脚本在Gmail ss/465和tls/587上运行良好.

My Script is working fine with Gmail ss/465 and tls/587.

谢谢! @Synchro.

Thanks! @Synchro.

这篇关于有时在本地主机的gmail端口465或587上,PHPMailer无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆