I am using Laravel Mail function to send email. The following is my app/config/mail.php
file settings.
'driver' => 'sendmail',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'email@gmail.com', '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('EmailId@hotmail.com', 'Sender Name')->subject('Welcome!');
});
When I run the code it gives me following error message:
Swift_TransportException
Expected response code 220 but got code "", with message ""
I have created a SendMail.php
file in view which contains some data.
How do I resolve this error message?
For me the problem was the port. I first incorrectly used port 465, which works for
SSL
but notTLS
. So the key thing was changing the port to 587.What helped me... changing sendmail parameters from -bs to -t.
I did as per sid saying my env after updating is
this did work without 2 step verification. with 2 step verification enabled it did not work for me.
This problem can generally occur when you do not enable two step verification for the
gmail
account (which can be done here) you are using to send anemail
. So first, enabletwo step verification
, you can find plenty of resources for enabling two step verification. After you enable it, then you have to create anapp password
. And use theapp password
in your.env
file. When you are done with it, your.env
file will look something like.and your
mail.php
After doing so, run
php artisan config:cache
andphp artisan config:clear
, then check, email should work.In my case I had to set the
to work it.. Might be useful. Rest of the code was same as @Sid said.
And I think that editing both environment file and app/config/mail.php is unnecessary. Just use one method.
Edit as per the comment by @Zan
If you need to enable tls protection use following settings.
See here for some other gmail settings
if you are using Swift Mailer: please ensure that your $transport variable is similar to the below, based on tests i have done, that error results from ssl and port misconfiguration. note: you must include 'ssl' or 'tls' in the transport variable.
EXAMPLE CODE: