Sending email with Laravel 5.2

Asked

Viewed 6,501 times

7

I’m having trouble emailing with Laravel 5.2. You’re returning this mistake to me:

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

The archive .env is 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 into gmail normal with the email and password I put on .env.

The archive config/mail.php is 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 e-mailing like this:

Mail::send('emails.recuperar-senha', $dados, function ($message) {
            $message->to(Input::get('email'));
}); 
  • You’re testing it locally or on the web ?

  • I’m trying to locally.

  • I read "madly". Rsrsrs I have this problem here on my Localhost. I can’t send anything by email. I always try it on the server and it works. To make a test, change the driver of smtp for mail.

  • 1

    I already found the problem. It’s with email. You need to give a permission to send SMTP by being in a domain other than google.com

1 answer

3

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

To test change the file config/mail 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 sending:

\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 did the tests with this configuration and sent normally.

  • I changed the code as you said, continue with the same error.

  • Do the following, change the email data in place by placing your personal email and try to send it to yourself. Since it is authentication error. To see if there is some configuration in the email.

  • I tried that, it was the same mistake.

  • I changed my reply with a test email that I registered in gmail and sent normally.

  • 1

    I already found the problem. It’s with email. You need to give a permission to send SMTP by being in a domain other than google.com

  • I recommend that you use Mailtrap to do your tests. https://mailtrap.io/

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.