Anvar  Abdulsatarov
Anvar Abdulsatarov

Reputation: 97

Mail::send() method is null

That's my web.php where the routes are located

Route::group([], function(){

Route::match(['get', 'post'], '/', ['uses'=>'IndexController@execute', 'as'=>'home']);
Route::get('/page/{alias}', ['uses'=>'PageController@execute', 'as'=>'page']);

Route::auth();});

.env file:

MAIL_DRIVER=log
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=

[email protected]

and that's that's my IndexController execute method

$result = Mail::send('site.email', ['data'=>$data], function($message) use ($data) {

            $mail_admin = env("MAIL_ADMIN");

            $message->from($data['email'], $data['name']);
            $message->to($mail_admin, "Anvar AKA")->subject('Question');

        });
        dump($result);
        if($result){
            return redirect()->route('home')->with('status', 'Email is sent');
        }

It stores the message into laravel.log file but the $result after the submission of the form is null. How to fix it? I need to store there the data

Upvotes: 1

Views: 2317

Answers (1)

MohamedSabil83
MohamedSabil83

Reputation: 1559

That's because Mail::send doesn't return value. instead, you can check Mail::failures like that:

if(count(Mail::failures()) > 0){
    // Your error message or whatever you want.
}

Upvotes: 1

Related Questions