Laravel 5: Sending Email
Solution 1
Well, I got it. Infact the email was not authenticated because that email required a mobile phone authentication after login. changing to other email address that required just login credentials, it worked.
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
Solution 2
GMail SMTP requires encryption. Try changing setting as following.
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
Solution 3
I made the following mistake: I did not actually include the
'encryption' => env('MAIL_ENCRYPTION'),
to the array return in mail.php. I did include my host, port, username and password in the mail.php but not the encryption method (the encryption method I only included in the .env file), so trying out these mentioned solutions did bring a change in the error messages outcome, created a bigger confusion, but none solved the problem. Hope this helps someone!
Saani
A versatile and professional web application developer with a commitment to develop & work with innovative & creative web solutions.
Updated on January 25, 2020Comments
-
Saani over 4 years
I am trying to send an email in laravel application. Here is my
.env
file:MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 [email protected] MAIL_PASSWORD=********** MAIL_ENCRYPTION=tls
And here is the
Mail::send
method:Mail::send('email', ['name' => "EE"], function($m){ $m->to('[email protected]', 'Malik')->subject('Subjet of the email'); });
And here is the error:
Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. s16sm7748968wib.16 - gsmtp"
Any help?
-
Tarunn almost 9 yearswhere are you using this code, local or server?
-
Saani almost 9 yearsIf u mean the Mail::send(---) code, then i m using it in Controller.
-
Tarunn almost 9 yearsI mean... u r on localhost or Server!?
-
Ash almost 9 yearsIt's just an authentication error. I would suggest following the instructions of the error message
530 5.7.0 Must issue a STARTTLS command first. s16sm7748968wib.16 - gsmtp
. -
Ash almost 9 yearsA quick google get's this... richardwillia.ms/blog/2010/12/swift-mailer-starttls - I hope it helps
-
Saani almost 9 yearsyeah, i m on localhost..
-
Saani almost 9 yearsI am not using swift mailer @Ash, I am using laravel, so how to deal with starttls problem in laravel, any idea?
-
Ash almost 9 yearsLaravel uses Swift mailer which is also a Symfony component.
-
-
Saani almost 9 yearstried with no benefit, giving the error: Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. w8sm20719292wja.15 - gsmtp "
-
Tarunn almost 9 yearswhat is your driver settings
'driver' => env('MAIL_DRIVER', 'smtp')
in mail config?? -
Saani almost 9 yearsThis is the driver settings:
'driver' => env('MAIL_DRIVER', 'smtp')
-
Saani almost 9 yearsThis is host:
'host' => env('MAIL_HOST', 'smtp.gmail.com')
and this is port:'port' => env('MAIL_PORT', 465)
in mail config file -
Tarunn almost 9 yearsother settings like driver, port, host in config??
-
Ash almost 9 yearsyour
.env
fileMAIL_HOST
should be this:MAIL_HOST=smtp.gmail.com
. Theenv()
function will attempt to load a variable from the.env
or use the default:env('KEY', 'the default')
. (this is for someone who comes here with the same issue) -
Dov Benyomin Sohacheski over 6 yearsIs this a suggestion or an answer?