繁体   English   中英

Bluehost上Google Suite的PHPMailer SMTP设置

[英]PHPMailer SMTP settings for Google Suite on Bluehost

我正在尝试使用PHPMailer和我的Google Suite电子邮件(info@mydomain.com)使用PHP发送电子邮件。

在阅读了Stack Overflow的其他文章并尝试了所有方法之后,我无法使其工作。 我还在正确的g套件帐户中将“允许不太安全的应用程序”设置为“ true”。

这是我不断得到的错误:

使用SSL和端口465:

2019-09-11 22:27:33 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array()
2019-09-11 22:27:33 Connection failed. Error #2: stream_socket_client(): Peer certificate CN=`*.bluehost.com' did not match expected CN=`smtp.gmail.com' [/home2/.../includes/PHPMailer/src/SMTP.php line 326]
2019-09-11 22:27:33 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [/home2/lucapenn/public_html/algofinder.com/admin/includes/PHPMailer/src/SMTP.php line 326]
2019-09-11 22:27:33 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) [/.../includes/PHPMailer/src/SMTP.php line 326]
2019-09-11 22:27:33 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

使用TLS和端口587:

2019-09-12 08:12:39 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2019-09-12 08:12:39 Connection: opened
2019-09-12 08:12:39 SMTP INBOUND: "220-box5141.bluehost.com ESMTP Exim 4.92 #2 Thu, 12 Sep 2019 03:12:39 -0500"
2019-09-12 08:12:39 SMTP INBOUND: "220-We do not authorize the use of this system to transport unsolicited,"
2019-09-12 08:12:39 SMTP INBOUND: "220 and/or bulk e-mail."
2019-09-12 08:12:39 SERVER -> CLIENT: 220-box5141.bluehost.com ESMTP Exim 4.92 #2 Thu, 12 Sep 2019 03:12:39 -0500 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2019-09-12 08:12:39 CLIENT -> SERVER: EHLO mydomain.com
2019-09-12 08:12:39 SMTP INBOUND: "250-box5141.bluehost.com Hello mydomain.com [162.241.224.176]"
2019-09-12 08:12:39 SMTP INBOUND: "250-SIZE 52428800"
2019-09-12 08:12:39 SMTP INBOUND: "250-8BITMIME"
2019-09-12 08:12:39 SMTP INBOUND: "250-PIPELINING"
2019-09-12 08:12:39 SMTP INBOUND: "250-AUTH PLAIN LOGIN"
2019-09-12 08:12:39 SMTP INBOUND: "250-STARTTLS"
2019-09-12 08:12:39 SMTP INBOUND: "250 HELP"
2019-09-12 08:12:39 SERVER -> CLIENT: 250-box5141.bluehost.com Hello algofinder.com [162.241.224.176]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2019-09-12 08:12:39 CLIENT -> SERVER: STARTTLS
2019-09-12 08:12:39 SMTP INBOUND: "220 TLS go ahead"
2019-09-12 08:12:39 SERVER -> CLIENT: 220 TLS go ahead
2019-09-12 08:12:39 Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate CN=`*.bluehost.com' did not match expected CN=`smtp.gmail.com' [/home2/.../PHPMailer/src/SMTP.php line 405]
SMTP Error: Could not connect to SMTP host.
2019-09-12 08:12:39 CLIENT -> SERVER: QUIT
2019-09-12 08:12:39
2019-09-12 08:12:39 SMTP INBOUND: ""
2019-09-12 08:12:39
2019-09-12 08:12:39
2019-09-12 08:12:39 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

这是我的PHP代码:

$mail = new PHPMailer(true);

try {

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 4; 
$mail->SMTPAuth = true;  // authentication enabled
$mail->SMTPSecure = 'ssl'; //or SSL
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; //or 587
$mail->Username = 'info@mydomain.com';  
$mail->Password = 'mypassword';           

$mail->setFrom($from, 'MyDomain');
$mail->addAddress($to);   

$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body_html;
$mail->AltBody = $body_txt;

$mail->send();

} catch (Exception $e) {

echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";

}

我只想向收件箱中发送一些普通电子邮件。 PHPMailer和Google Suite可以吗? 还有其他更可靠的解决方案可以到达收件箱吗?

这是您的问题:

2019-09-11 22:27:33连接失败。 错误2:stream_socket_client():对等证书CN = *.bluehost.com' did not match expected CN= smtp.gmail.com' *.bluehost.com' did not match expected CN= [/home2/.../includes/PHPMailer/src/SMTP.php第326行]

您要连接到smtp.gmail.com ,但最终要连接到bluehost.com主机。 这是因为您的托管服务提供商正在使用防火墙将端口465上的出站流量重定向到他们自己的邮件服务器。 由于证书名称不匹配,这导致证书验证失败。 从这个意义上讲,TLS完全按照预期的方式工作,可以检测到什么构成中间人攻击。 但是,鉴于您知道此“攻击者”是谁,这并不是特别有用。 Bluehost可能已进行了一些安排,使您可以通过自己的邮件服务器发送电子邮件,并且如果您切换到它,则证书名称将匹配。

请记住,即使您确实解决了此问题,也有另一个问题在等待您:gmail具有严格的SPF和DMARC设置,这意味着除非您通过gmail自己的服务器发送邮件,否则您无法从gmail.com地址发送电子邮件。 如果您将自己的域名与gmail一起使用,则可以至少将Bluehost的SPF记录添加到自己的域名中,以允许从那里进行发送。

从错误消息链接的疑难解答指南中涵盖了这种确切情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM