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

4

8

I am trying to use 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?

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"
Upbuild answered 16/5, 2017 at 13:11 Comment(3)
May you need execute php artisan config:cache or php artisan cache:clear?Handle
Please try to debug your dd(env('MAIL_HOST')); And clear your cache.Fortner
dd(env('MAIL_HOST')); is nullUpbuild
F
11

It's look like your .ENV still have cache.

Please try this way

php artisan config:cache
php artisan cache:clear

And try to debug at your Controller

dd(env('MAIL_HOST'));

If it's still get smtp.gmail.com. Please try this way.

Edit your config/app.php. And add below 'env' => env('APP_ENV', 'production'),

'mail_host' => env('MAIL_HOST', 'smtp.mailgun.org'),

And try to debug at your Controller

dd(config('app.mail_host'));

I'm sure it's will show smtp.mailgun.org

After that you can delete the line you has just added to config/app.php

Fortner answered 16/5, 2017 at 13:49 Comment(0)
K
14

My MAIL_HOST was mailtrap.io, and it seems that that URL is not valid any more.

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

Knelt answered 9/3, 2018 at 15:41 Comment(4)
This was causing issues for me just a moment ago – very good to know!Sloe
Wow, thank you. I was banging my head - this helped!Atheistic
This is the exact solution to my problem. Thanks a lot.Mosenthal
I was going insane due to this reason. Thanks a lot. It helped.Suanne
F
11

It's look like your .ENV still have cache.

Please try this way

php artisan config:cache
php artisan cache:clear

And try to debug at your Controller

dd(env('MAIL_HOST'));

If it's still get smtp.gmail.com. Please try this way.

Edit your config/app.php. And add below 'env' => env('APP_ENV', 'production'),

'mail_host' => env('MAIL_HOST', 'smtp.mailgun.org'),

And try to debug at your Controller

dd(config('app.mail_host'));

I'm sure it's will show smtp.mailgun.org

After that you can delete the line you has just added to config/app.php

Fortner answered 16/5, 2017 at 13:49 Comment(0)
D
2

In your .envfile you should set

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

Dorwin answered 16/5, 2017 at 13:22 Comment(0)
G
1

After

php artisan config:cache
php artisan cache:clear

You probably also need to restart your web server.

Goldarned answered 22/2, 2019 at 10:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.