How can I solve quot;Connection could not be established with host smtp.gmail.comquot;?(如何解决“无法与主机 smtp.gmail.com 建立连接?)
问题描述
如果我确实在我的本地主机上发送电子邮件,它可以工作.没有错误
If I do send email on the my localhost, it works. No error
但我在登台服务器上尝试,它显示如下错误:
But I try on the staging server, it display error like this :
Swift_TransportException in StreamBuffer.php line 268:
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
in StreamBuffer.php line 268
at Swift_Transport_StreamBuffer->_establishSocketConnection() in StreamBuffer.php line 62
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'tcp', 'host' => 'smtp.gmail.com', 'port' => '587', 'timeout' => '30', 'blocking' => '1', 'tls' => true, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
at Swift_Transport_AbstractSmtpTransport->start() in Mailer.php line 79
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 395
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 217
...
我的环境是这样的:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=secret@gmail.com
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=tls
来自谷歌的一些参考(通过 Laravel 使用 gmail smtp:无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]),我尝试了一些答案.我尝试将邮件端口和邮件加密更改为这样:
From some reference on the google (Using gmail smtp via Laravel: Connection could not be established with host smtp.gmail.com [Connection timed out #110]), I try some answer. I try change mail port and mail encryption to be like this :
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
没有用
我再次尝试更改:
MAIL_DRIVER=sendmail
它也不起作用
我在这里 on
:https://myaccount.google.com/lesssecureapps
都一样
我试试:
php artisan cache:clear
php artisan config:cache
还是不行
我的服务器使用 gitlab、forge laravel 和数字海洋
My server using gitlab, forge laravel and digital ocean
以前在临时服务器上发送邮件可以,但是在我在 forge laravel 上重新安装存储库后,它现在无法正常工作
Previous send mail on the staging server worked, but after I re-install the repository on the forge laravel, it now does not work
我需要设置什么?
推荐答案
几天前我遇到了完全相同的问题,我到处搜索laracast stackoverflow和许多github问题,终于解决了问题.
Few days ago I've faced exactly the same problem and I've searched everywhere like laracast stackoverflow and many github issues and finally solve the problem.
你需要这样的配置,
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=youremail@gmail.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=ssl
完成此设置后,您应该确保您的 google 帐户 2 步验证
已关闭,因为这增加了额外的安全层,这就是无法建立连接的原因.
After this setup you should make sure that your google account 2 step verification
is turned off because this adds an extra layer of security that's why connection can't be established.
我认为这是谷歌最近添加的新功能.我以前进行过邮件配置,但最近相同的代码不起作用.
I think this is new feature added by google recently. I've working mail configuration before but recently same code doesn't work.
您可以转到您的 google 帐户,在那里您将看到 登录和安全 选项卡.单击它,您将在此处看到 2 步验证.然后你需要关闭它.然后我认为它会起作用.
You can go to your google account where you will see Sign-in and Security tab. Click on it then you will see 2 step verfication there. Then you need to turn off that. Then I think it'll work.
这件事对我有用,我希望它也对你有用.希望你能理解.
This thing worked for me I hope it'll work for you as well. I hope you understand.
这篇关于如何解决“无法与主机 smtp.gmail.com 建立连接"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何解决“无法与主机 smtp.gmail.com 建立连接"?
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01