Sending email in laravel returns the error:
[Swift_TransportException]
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
"
Install the following lib.
1. Add in composer.json
"require": {
"guzzlehttp/guzzle": "~5.3|~6.0"
},
2. Run composer update
Set the env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxx@gmail.com
MAIL_PASSWORD=xxxx
MAIL_ENCRYPTION=tls
Set config/mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'dev.thowfeek@gmail.com', 'name' => 'Thowfeek'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME', 'xxxx@gmail.com'),
'password' => env('MAIL_PASSWORD', 'xxxx'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
If the following error returns, set the config in gmail account.
[Swift_TransportException]
Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/answer/14257 a87sm1164316pfc.63 - gsmtp
"
Gmail > My Account > Sign-in & security
Allow less secure apps: ON
Code in the controller
$data = array('user' => array('name' =>'Thowfeek'));
Mail::send('emails.reminder', $data, function ($message) {
$message->from('thowfeek@gmail.com', 'Learning Laravel');
$message->to('thowfeek@yahoo.com')->subject('Learning Laravel test email');
});
Code in the view emails/reminder.blade.php
<h2>this is a reminder email</h2>
<p>{{ $user['name'] }}</p>
Sign up here with your email