Shweta
Shweta

Reputation: 1212

Connection could not be established with host smtp.gmail.com Laravel

I am trying to send a mail to my email-id. I have followed all the steps that might required to send a mail.

But it keeps on coming 2 errors

  1. 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]

  2. Maximum execution time of 30 seconds exceeded.

my controller is

public function contact()
    {
   Mail::send('clientinfo.contact',['name' => 'shweta'],function($message){
            $message->to('[email protected]','Some Name')->subject('Welcome!')->from('[email protected]');
           });

mail.php file :

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => '[email protected]', 'name' => 'Some  One Sender'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
 'pretend' => false,

];

Please help me through this.

Upvotes: 1

Views: 8118

Answers (3)

max
max

Reputation: 1

Use the MAIL_PORT=587 instead of the default mail_port in your .env file.

Upvotes: 0

AmarjaPatil4
AmarjaPatil4

Reputation: 1650

Make sure you install Guzzle to your project by adding the following line to your composer.json file:

"guzzlehttp/guzzle": "~5.3|~6.0"

and editing your .env file with real email-id and password. Also, enable, less secure apps for that email-id as told by @Bharat Geleda

then your above code will run properly.

Upvotes: 2

Rabb-bit
Rabb-bit

Reputation: 835

This is what I did.

  1. I enabled two step verification on may gmail account

  2. created separate apps password for my app here (screenshot below) (https://security.google.com/settings/security/apppasswords)

  3. I that password into my laravel .env file and it worked.

screenshot just select "Other(custom name)" on the "select app" and it will generate a password for you.

enter image description here

Upvotes: 0

Related Questions