"Expected Response code 220 but got an Empty Response" when sending email

Asked

Viewed 1,777 times

0

I am trying to send an email using the Standard.

I tried something like:

api.php:

Route::get('emailAnimalEncontrado', function () {
    $data = array(
        'name' => 'Novo animal encontrado em Franca. Você pode ajudá-lo?'
    );

    Mail::send('email', $data, function ($message){
        $message->from('[email protected]', 'Novo animal encontrado em francaa.');
        $message->to('[email protected]')->subject('teste email laravel');
    });
    return response()->json('Email enviado com sucesso', 201);
});

my file . env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=SENHAEMAIL
MAIL_ENCRYPTION=null

In Resources/views/email.blade.php:

<html lang="pt-br">
<head>
    <meta charset="utf-8"/>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
</head>
<body>

    OI MUNDO

</body>
</html>

In mail.php:

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
  'port' => env('MAIL_PORT', 465),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Renato Veronese'),
    ],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('[email protected]'),

    'password' => env('SENHAEMAIL'),

 'sendmail' => '/usr/sbin/sendmail -bs',


    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
  • 1
  • I changed to MAIL_USERNAME, remains the same problem.

  • Also has a env('SENHAEMAIL') lost there. Change and rotate the php artisan config:cache.

1 answer

1

Gmail has some security that may be affecting your code in ways that are not as clear as they should be. Do it like this: in your file. env, change the value of the variable MAIL_ENCRYPTION to tls, instead of having it null.

A priori, everything should start working properly. However, if you continue with the same problem, according to this article https://artisansweb.net/sending-email-via-gmail-smtp-server-laravel/, you must go to your Gmail account and activate the option to allow access from less secure applications.

Browser other questions tagged

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