"Expected response code 220 but got an empty response" when sending email laravel

0

I'm trying to send an email using laravel.

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 .env file:

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'),
        ],
    ],
    
asked by anonymous 22.12.2018 / 16:01

1 answer

0

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

A priori, everything should start working correctly. However, if you continue with the same problem, please link , you should go to your GMail account and enable the option to allow access to less secure applications.

    
30.12.2018 / 01:11