【发布时间】:2016-10-19 02:22:28
【问题描述】:
我知道这个问题被问了很多次并且有不同的解决方案,我已经尝试了所有但没有一个成功。这是我的设置。
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=abc@mydomain.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
应用程序当前正在Centos 7 OS 上运行。
我总是得到
Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => '465', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
我已经尝试了所有解决方案,通过替换:smtp.gmail.com with 173.194.65.108,或替换 smtp.gmail.com by gmail-smtp-msa.l.google.com。当我执行这两个步骤时,出现 server not found 错误。
如果我从 smtp to sendmail or mail 更改邮件驱动程序,则不会引发错误但不会发送电子邮件。
如果我使用 smtp.gmail.com 的 IP 地址,我会得到相同的结果。如果我从465 to 587 更改端口并从ssl to tls 更改加密,则没有任何反应。
我还在etc/gai.conf 中创建了一个文件并放入precedence ::ffff:0:0/96 100。它工作了一次。但过了两个小时后,它停止工作并开始抛出同样的错误。
我也尝试过使用我的 gmail id,但都是徒劳的。
我无法测试的唯一解决方案是验证httpd_can_sendmail,因为每当我运行命令getsebool httpd_can_sendmail 我得到getsebool: SELinux is disabled。这是问题还是有其他方法可以解决?
【问题讨论】:
-
将端口更改为
587和tls为true,并允许不安全的应用进行身份验证 -
在我的情况下,我的主机阻止了外部 smtp 连接。如果您要使用 Mailgun 的 API,这将不是问题。
标签: php laravel email sendmail