Unable to send e-mail to laravel 5.2

advertisements

I am trying to send an email with laravel 5.2 . This is my first time of sending email in laravel. But it is throwing this error

This is the error

Swift_TransportException in AbstractSmtpTransport.php line 162: Cannot send message without a sender address

This is my code of sending email

Route::get('test',function(){
    $message  = "hello";
    Mail::send('welcome', ['key' => 'value'], function($message)
    {

       $message->to('[email protected]', 'John Smith')->subject('Welcome!');
    });
});

This is my email settings in env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=xxxxxx

MAIL_ENCRYPTION=null

My welcome view only has a message "Hello world"

I already configured less secure app settings for my email in gmail settings. So please what is wrong with my code ? Why is that throwing that error ?


The error message Cannot send message without a sender address is clear. You just need to add from to the message:

Route::get('test',function(){
    $message  = "hello";
    Mail::send('welcome', ['key' => 'value'], function($message)
    {

       $message->from('[email protected]')
           ->to('[email protected]', 'John Smith')
           ->subject('Welcome!');
    });
});

In order to be able to send the mail you must to change the mail encryption in the .env file to:

MAIL_ENCRYPTION=tls