Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
like image 927
LeBlaireau Avatar asked May 16 '17 13:05

LeBlaireau


4 Answers

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.

like image 68
Mladen Janjetovic Avatar answered Nov 18 '22 23:11

Mladen Janjetovic


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

like image 32
Quynh Nguyen Avatar answered Nov 19 '22 00:11

Quynh Nguyen


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

like image 2
Rezrazi Avatar answered Nov 19 '22 00:11

Rezrazi


After

php artisan config:cache
php artisan cache:clear

You probably also need to restart your web server.

like image 1
Rajesh Chaudhary Avatar answered Nov 19 '22 01:11

Rajesh Chaudhary