I'm trying to send email using laravel 5.4 but I'm getting this error. I try to enable less secure application for my account but nothing seems to work for me. this is my code:

use Mail;

class UserController extends Controller{
    public function register(Request $request)
    {
        $inputs=$request->all();
        $data=$inputs;
        Mail::send('mail.ajout', $data, function($message) use ($data)
        {
            $message->from($data['email']);
            $message->subject("Nouvelle inscription");
            $message->to('[email protected]');
        });

    }
}

my env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_USERNAME= [email protected]
MAIL_PASSWORD= mypwd
MAIL_ENCRYPTION=tls

mail.php

<?php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],  
    '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'),
        ],
    ],
];

any help please ,thanks in advance

1

There are 1 answers

2
Sagar Chamling On

Is there space in after .env variable = ? Then just remove it takes space as a character.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
[email protected]
MAIL_PASSWORD=mypwd
MAIL_ENCRYPTION=tls

After changing .env clear your config and restart your server.

php artisan config:clear
php artisan serve