I have a problem when sending an account confirmation email, I try it on the localhost and it works correctly, but when I deploy the application to heroku it does not send the email, this is my register method:
protected function register(Request $request)
{
$input = $request->all();
$validator = $this->validator($input);
$tutor = Role::where('name','tutor')->first();
if ($validator->passes()) {
$data = $this->create($input)->toArray();
$data['token'] = str_random(25);
$user = User::find($data['id']);
$user->token = $data['token'];
$user->save();
Mail::send('mails.confirmation', $data, function ($message) use($data){
$message->to($data['email']);
$message->subject('Registration Confirmation');
});
return redirect(route('login'))->with('status', 'Se ha enviado el correo electrónico de confirmación. Por favor, revise su bandeja de entrada.');
}
return redirect(route('login'))->with('status', $validator->errors());
}
When doing the registration the new user saves in the BD but does not send the confirmation email, it only shows this error:
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "530", with message "530-5.5.1
Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/?p=WantAuthError
t22sm5492950qke.49 - gsmtp"
This is my mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Discapp'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
And these are the configurations in my .env:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=dmxsxcrowuaadkco
MAIL_ENCRYPTION=tls
I would appreciate any recommendation, it took several days without being able to make it work.