Error sending mail from heroku-laravel 5.4

0

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.

    
asked by DVertel 21.04.2017 в 05:03
source

1 answer

0

@DVertel

We recently happened and after trying several things, we solved it provisionally by activating the "Access of less secure applications" in the GMail account that was being used for the shipment.

  

To keep the accounts of G Suite users secure, we may block access to less secure apps to G Suite accounts. If you are a G Suite user, you will see the error "Incorrect password" when you try to access. If this is the case, you have two options:

     

Option 1: Upgrade to a more secure app that uses the latest security measures. All Google products, such as Gmail, use updated security measures.

     

Option 2: Change settings to allow less secure apps to access the account. We do not recommend this option, as it could facilitate third party access to the account. If, however, you want to grant access, follow these steps:

     

Go to the Less secure apps section in "My account."   Select Activate next to "Access for less secure applications." (Note to G Suite users: This configuration option will be hidden if the administrator blocked the access of less secure apps to the account) .

Reference: link

    
answered by 30.04.2017 в 18:10