为什么我的在线联系表格在使用我的主机发送后会产生警告和致命错误';s中继,但不是与谷歌';s


Why does my online contact form produce a Warning and Fatal Error when after sending utilising my host's relay, but not with Google's?

我最近使用Google SMTP中继和Swiftmailer在XAMPP中测试后,在线迁移了一个web表单。谷歌中继使用我自己的收件箱绝对没有问题,然而,当试图切换到我的托管提供商(Siteground)推荐的中继和说明,也使用基于域的电子邮件时,我的表格正在发送中,我收到以下信息:

Warning: stream_socket_enable_crypto(): Peer certificate CN=`*.sgcpanel.com' did not match expected CN=`uk2.siteground.eu' in /home/tho/public_html/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 95
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Unable to connect with TLS encryption' in /home/tho/public_html/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php:289 Stack trace: #0 /home/tho/public_html/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(118): Swift_Transport_EsmtpTransport->_doHeloCommand() #1 /home/tho/public_html/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #2 /home/tho/public_html/sendmessage.php(30): Swift_Mailer->send(Object(Swift_Message)) #3 {main} thrown in /home/tho/public_html/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php on line 289

请注意,电子邮件帐户本身运行良好。它是在Mac Mail中设置的,发送和接收都没有任何问题。

我的托管提供商正在尝试,但我不认为他们能理解我遇到了什么问题。我最终把它缩小到了交通功能。请参阅下面的PHP代码:

谷歌(按预期工作):

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
        ->setUsername('foobar@googlemail.com')
        ->setPassword('APP GENERATED PASSWORD');

主机提供商(不按预期工作):

$transport = Swift_SmtpTransport::newInstance('uk2.siteground.eu', 25, 'tls')
    ->setUsername('email@mydomain.com')
    ->setPassword('MY EMAIL PASSWORD');

代码对我来说似乎还可以,因为它只是交换细节。这些是Siteground提供的设置。

到目前为止,我已经尝试了以下内容:

  • 在2525、25887和465之间更改端口,但没有成功
  • 在TLS和SSL之间切换失败
  • 更改了我的密码,尝试了各种组合而没有特殊设置没有成功的人物
  • 尝试在谷歌上搜索"Swiftmailer Siteground SMTP等"的所有排列,但没有出现任何结果
  • 将Swiftmailer更新到服务器端的最新版本,但没有成功

我已经提出了更多的问题,他们已经为我更新了PHP服务器端。现在没有显示错误,只显示数字0(即"0")。电子邮件也没有发送,但这是一个单独的问题,目前。

从错误消息来看,服务器uk2.siteground.eu上的SSL证书似乎不包括服务器的正确主机名,而是sgcpanel.com的通配符。587上的证书不包含uk2.site地线.eu作为服务器的有效名称。

如果您使用的是php5.6,他们会更改默认值以验证证书的对等名称。

正确的解决方案是Siteground向服务器添加正确的证书。你可能会在github上使用最新版本的SwiftMailer来覆盖这些检查。

9月份添加的setStreamOptions可能会解决您的问题,但如果不检查它是否是与其通信的正确服务器,则会降低安全性。

我现在无法测试,但请尝试:

$ssl_options = array(
   'ssl'         => array(
      'verify_peer'       => false,
      'verfify_peer_name' => false,
    ),
);
$transport->setStreamOptions($ssl_options);

或者阵列可能是

$ssl_options = array(
   'verify_peer'       => false,
   'verfify_peer_name' => false,
);
$transport->setStreamOptions($ssl_options);

更多信息:

http://php.net/manual/en/context.ssl.php

https://github.com/swiftmailer/swiftmailer/issues/571

答案由我的主机提供。他们对PHP服务器端进行了一些修改。起初没有成功,但在等待了大约一个小时后,这解决了问题。

好吧,也许不是从理想的意义上分类的,但至少作为一种变通方法。

相关文章: