dhamo dharan
dhamo dharan

Reputation: 138

How to check email sent or not in laravel 5

I have a function to send a email for registered users. This is how i am checking if an email should be sent or not.

$email=$details->email;
$subject = 'Looking for blood donor';
$status=Mail::send('emails.welcome', $data, function($message)
                        use($subject,$email){
                        $message->from('[email protected]', 'Blood Link');
                        $message->bcc('[email protected]');
                        $message->to($email)->subject($subject);
                    });

I am using if for check email sent or not but it not work..

if($status)
{
    return Response::json(array('status'=>'success',
                                'data'=>("Your email has been sent successfully")
                         ), 200);
}else{
    return Response::json(array('status'=>'error',
                                'data'=>("something went wrong..!!")
                         ), 200);
}

Upvotes: 0

Views: 6470

Answers (2)

Qazi
Qazi

Reputation: 5135

Have a look into failure method, here

Upvotes: 2

Drudge Rajen
Drudge Rajen

Reputation: 7987

The Mail::send() method doesn't return anything.

You can use the Mail::failures() (introduced in 4.1 I think) method to get an array of failed recipients, in your code it would look something like this.

Mail::send('emails.users.reset', compact('user', 'code'), function($m) use ($user)
{
    $m->to($user->email)->subject('Activate Your Account');
});

if(count(Mail::failures()) > 0){
    $errors = 'Failed to send password reset email, please try again.';
}

Upvotes: 5

Related Questions