Laravel 5: Sending Email

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?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

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!

Solution 4

If the above comments do not work, try clearing the cache:

php artisan cache:clear
php artisan config:clear

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply