E-mail sending with Laravel 5.2 [closed]

7

I'm having trouble sending mail with laravel 5.2. You are returning this error:

Expected response code 250 but got code "530", 
with message "530-5.5.1 Authentication Required.

The file .env looks like this:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls

The company's email domain is hosted on Google. I can log in to normal gmail with the email and password I put in .env .

The file config/mail.php looks like this:

return [

    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => '[email protected]', 'name' => 'teste'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('[email protected]'),
    'password' => env('****'),
    'sendmail' => '/usr/sbin/sendmail -bs',

];

I'm sending emails like this:

Mail::send('emails.recuperar-senha', $dados, function ($message) {
            $message->to(Input::get('email'));
}); 
    
asked by anonymous 01.08.2016 / 19:01

1 answer

3

To ensure that everything is correct and to identify the authentication error I created a test email in gmail:

For testing change the config/mail file as follows:

return [
   'driver' => env('MAIL_DRIVER', 'smtp'),
   'host' => env('MAIL_HOST', 'smtp.gmail.com'),
   'port' => env('MAIL_PORT', 587),
   'from' => ['teste' => '[email protected]','name' => 'teste'],
   'encryption' => env('MAIL_ENCRYPTION', 'tls'),
   'username' => env('MAIL_USERNAME','[email protected]'),
   'password' => env('MAIL_PASSWORD','testeti1'),
   'sendmail' => '/usr/sbin/sendmail -bs',


];

and for shipping:

\Mail::send('emails.recuperar-senha',$dados, function ($message)use($request){
        $message->from(\Config::get('mail.from.teste'))
                ->to('[email protected]')
                ->subject('Assunto do e-mail');
    });

I tested them with this configuration and sent them normally.

    
01.08.2016 / 19:11