Kirmani88 Kirmani88 - 6 months ago 5x
PHP Question

Expected response code 220 but got code "", with message "" in Laravel

I am using Laravel Mail function to send email. The following is my

file settings.

'driver' => 'sendmail',
'host' => '',
'port' => 587,
'from' => array('address' => '', 'name' => 'MyName'),
'encryption' => 'tls',
'username' => 'myUsername',
'password' => "password",
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

Controller Mail Method

//Send Mail
Mail::send('sendMail', array('key' => 'value'), function($message)
$message->to('', 'Sender Name')->subject('Welcome!');

When I run the code it gives me following error message:


Expected response code 220 but got code "", with message ""

I have created a
file in view which contains some data.

How do I resolve this error message?

Sid Sid

This problem can generally occur when you do not enable two step verification for the gmail account you are using to send an email. So first, enable two step verification, you can find plenty of resources for enabling two step verification. After you enable it, then you have to create an app password. And use the app password in your .env file. When you are done with it, your .env file will look something like.

MAIL_USERNAME=<<your email address>>
MAIL_PASSWORD=<<app password>>

and your mail.php


return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', ''),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => '<<your email>>', 'name' => '<<any name>>'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,


After doing so, run php artisan config:cache and php artisan config:clear, then check, email should work.