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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:44:51  来源:igfitidea点击:

Laravel on Localhost - Connection could not be established with host smtp.gmail.com [Connection timed out #110]

laravelemailmailgunlaravel-mail

提问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_HOSTmailtrap.io,并且该 URL 似乎不再有效。

When I changed it to smtp.mailtrap.ioit started working again.

当我将其更改为它时,smtp.mailtrap.io它又开始工作了。

回答by Quynh Nguyen

It's look like your .ENVstill 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 .envfile 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 服务器。