无法在 Windows 7 中与主机 smtp.gmail.com 建立 Laravel 5 连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38821614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Connection could not be established with host smtp.gmail.com in windows 7
提问by paranoid
When I user mail function in laravel, show me this error
当我在 Laravel 中使用邮件功能时,显示此错误
Connection could not be established with host smtp.gmail.com [A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
10060]
无法与主机 smtp.gmail.com 建立连接 [连接尝试失败,因为连接方在一段时间后没有正确响应,或建立连接失败,因为连接的主机未能响应。
10060]
This is my .env
file config
这是我的.env
文件配置
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls
回答by Atiqur
In your local PC(with xampp/wamp) try the following steps if you want to work with Gmail
https://www.google.com/settings/security/lesssecureappsgive permission for lesser secured app
change your config like this
如果您想使用 Gmail,请在您的本地 PC(使用 xampp/wamp)尝试以下步骤
https://www.google.com/settings/security/lesssecureapps授予安全性较低的应用程序权限
像这样改变你的配置
MAIL_DRIVER='sendmail' MAIL_HOST='smtp.gmail.com' Or '173.194.65.108' MAIL_PORT=587 MAIL_USERNAME='[email protected]' MAIL_PASSWORD="secret" MAIL_ENCRYPTION="tls"
MAIL_DRIVER='sendmail' MAIL_HOST='smtp.gmail.com' Or '173.194.65.108' MAIL_PORT=587 MAIL_USERNAME='[email protected]' MAIL_PASSWORD="secret" MAIL_ENCRYPTION="tls"
- here important is driver - sendmail
- Clear you config -
- 这里重要的是驱动程序 - sendmail
- 清除你的配置 -
Artisan::call('view:clear'); Artisan::call('route:clear'); Artisan::call('config:clear'); Artisan::call('cache:clear'); Artisan::call('config:cache');
N.B - your cmd will be like: php artisan view:clear .....etc. Its important to clear your cache you change in .env . Me personally also restart the xampp as I read somewhere .env files load when apache starts!
Artisan::call('view:clear'); Artisan::call('route:clear'); Artisan::call('config:clear'); Artisan::call('cache:clear'); Artisan::call('config:cache');
注意 - 您的 cmd 将类似于:php artisan view:clear .....etc。清除您在 .env 中更改的缓存很重要。当我在 apache 启动时读取 .env 文件加载时,我个人也重新启动了 xampp!
Now try to send the mail , it should work if your network administrator did not blocked it[unintentionally! In my cases he even do not know for which change it stopped to sending mail]
I use these steps with laravel 5.2 and it worked fine but recently something is changed by either google Or My network administrator so its not sending mail from xampp but working fine in shared hosting.
现在尝试发送邮件,如果您的网络管理员没有阻止它,它应该可以工作[无意!在我的情况下,他甚至不知道停止发送邮件的更改]
我将这些步骤与 laravel 5.2 一起使用,它运行良好,但最近 google 或我的网络管理员更改了某些内容,因此它不会从 xampp 发送邮件,但在共享主机中运行良好。
N.B- I listed these because at least it worked on real hosting for which I spent much time to troubleshoot.
注意 - 我列出这些是因为至少它适用于我花了很多时间进行故障排除的真实托管。
回答by Juls Francisco
Just restart your XAMPP (both Apache and MySQL), and run again PHP Artisan, and your good to go.
只需重新启动您的 XAMPP(Apache 和 MySQL),然后再次运行 PHP Artisan,就可以了。
回答by Ayman Elshehawy
Make sure you install Guzzle to your project by adding the following line to your composer.json file:
通过将以下行添加到 composer.json 文件,确保将 Guzzle 安装到您的项目中:
"guzzlehttp/guzzle": "~5.3|~6.0"
reference Connection could not be established with host smtp.gmail.com Laravel