当前位置: 首页 > 知识库问答 >
问题:

Bluehost上Google套件的phpMail SMTP设置

吕征
2023-03-14

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

在阅读了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和谷歌套件可以吗?是否有其他更可靠的解决方案能够到达收件箱?

共有1个答案

裘禄
2023-03-14

这就是你的问题:

2019-09-11 22:27:33连接失败。错误2:stream#u socket_client():对等证书CN=*.bluehost.com'与预期的CN=smtp.gmail.com'[/home2/../includes/PHPMailer/src/smtp.php行326]不匹配

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

请记住,即使你确实解决了这个问题,还有另一个问题在等着你:gmail有严格的SPF和DMARC设置,这意味着你不能从gmail.com地址发送电子邮件,除非你通过gmail自己的服务器发送。如果你在gmail上使用自己的域名,你至少可以将Bluehost的SPF记录添加到你自己的域名中,这样就可以从那里发送。

错误消息链接的故障排除指南中介绍了这种情况。

 类似资料:
  • 我尝试的是下面的,但不是工作 从谷歌REST链接,它显示的例子如下,如何运行这个?

  • 当我从PHP Google App Engine实例在Google云存储中创建对象时,不会设置owner的ACL,因此以后无法更改缓存控制头之类的内容。 如何从PHP app engine设置更详细的ACL设置,而不是使用预定义的云存储ACL魔术设置(公共读取、所有者完全读取写入等)?

  • 本文向大家介绍BlueHost Windows主机控制面板介绍,包括了BlueHost Windows主机控制面板介绍的使用技巧和注意事项,需要的朋友参考一下 在BlueHost中文官网有Linux和Windows两种操作系统的虚拟主机,前者采用的是大家熟悉的cPanel控制面板,而Windows主机使用的则是Plesk面板。今天小编就给大家介绍一下BlueHost Windows主机的Plesk

  • 我的网站文件托管在Google Cloud Storage,每次我更新一个文件(比如。png或。xml)时,我总是要等一段时间才能看到新文件出现在我的页面上。 有没有办法覆盖单个对象的默认缓存设置(max-age=3600)?尝试用“no store”、“no cache”、“max-age=0”编辑“cache-control”元数据,但它们似乎都不起作用,仍然在响应头中获得“cache-con

  • 套件 套件可以手动下载安装,但有套件命令的帮助下,它可以更快的运作。 它透过定义在 fuel/core/config/package.php 的来源列表, 及任何其他可以编辑或複製到 fuel/app/config 文件夹的配置档案寻找套件。 Oil 很聪明,所以它在做任何套件命令之前,会检查是否你已经在你的电脑上安装 Git。 如果你已经安装 Git,Oil 会安装一个套件做为 Git 储存库,

  • 问题内容: 我们正在构建一个使用google maps api的应用程序。 我有MapController和MapView,并使用以下命令启用了内置的缩放控件: 我现在想在用户实际放大地图时得到一个事件,我该如何处理?我找不到能检测到缩放级别变化的此类事件或任何常规事件。 更新资料 mapView.getZoomControls()已弃用。并且文档建议改用mapView.setBuiltInZoo