Laravel on Localhost - 无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44002481/
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 on Localhost - Connection could not be established with host smtp.gmail.com [Connection timed out #110]
提问by LeBlaireau
I am trying to use Mailgun
我正在尝试使用 Mailgun
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
MAILGUN_DOMAIN=xxxxxxxxxx,
MAILGUN_SECRET=xxxxxxxxxx,
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
The error is a strange one. Why would it be trying to connect to gmail?
该错误是一个奇怪的错误。为什么它会尝试连接到 gmail?
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
Edit:
编辑:
Now I am getting
"mail" => array:9 [▼
"driver" => "smtp"
"host" => "smtp.mailgun.org"
"port" => "2525"
"from" => array:2 [?]
"encryption" => null
"username" => null
"password" => null
"sendmail" => "/usr/sbin/sendmail -bs"
"markdown" => array:2 [▼
"theme" => "default"
回答by Mladen Janjetovic
My MAIL_HOSTwas mailtrap.io
, and it seems that that URL is not valid any more.
我的MAIL_HOST是mailtrap.io
,并且该 URL 似乎不再有效。
When I changed it to smtp.mailtrap.io
it started working again.
当我将其更改为它时,smtp.mailtrap.io
它又开始工作了。
回答by Quynh Nguyen
It's look like your .ENV
still have cache.
看起来你.ENV
还有缓存。
Please try this way
请尝试这种方式
php artisan config:cache
php artisan cache:clear
And try to debug at your Controller
并尝试在您的 Controller
dd(env('MAIL_HOST'));
If it's still get smtp.gmail.com
. Please try this way.
如果它仍然得到smtp.gmail.com
. 请尝试这种方式。
Edit your config/app.php
. And add below 'env' => env('APP_ENV', 'production'),
编辑您的config/app.php
. 并在下面添加'env' => env('APP_ENV', 'production'),
'mail_host' => env('MAIL_HOST', 'smtp.mailgun.org'),
And try to debug at your Controller
并尝试在您的 Controller
dd(config('app.mail_host'));
I'm sure it's will show smtp.mailgun.org
我确定它会显示 smtp.mailgun.org
After that you can delete the line you has just added to config/app.php
之后,您可以删除刚刚添加到的行 config/app.php
回答by Rezrazi
In your .env
file you should set
在您的.env
文件中,您应该设置
MAIL_HOST=smtp.mailgun.org
MAIL_USERNAME=(yourmailgunusername)
MAIL_PASSWORD=(yourmailgunpassword)
MAIL_PORT=587
MAIL_DRIVER=mailgun
You can refer to these tutorials for more informations
Mailgun setup with Laravel 5 example
Ultimate Guide on Sending Email in Laravel
您可以参考这些教程了解更多信息
Mailgun setup with Laravel 5 example
Ultimate Guide on Sending Email in Laravel
回答by Rajesh Chaudhary
After
后
php artisan config:cache
php artisan cache:clear
You probably also need to restart your web server.
您可能还需要重新启动 Web 服务器。