Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Mail sending email but returning false

I am trying to send a email and show any errors if needed. The following code is sending a email and I am receiving it just fine. The issue though, is that when I do the check on the $sent var, it returns false for me.

Am I just missing something here? It might be because it's late. Who knows...

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

if( ! $sent)
{
    $errors = 'Failed to send password reset email, please try again.';
}
like image 776
Chris Casper Avatar asked Jul 16 '14 05:07

Chris Casper


People also ask

How can I check email is valid in Laravel?

You can check if an email is valid or not in Laravel using the validate method by passing in the validation rules.

What is mailable Laravel?

Laravel provides a clean, simple email API powered by the popular Symfony Mailer component. Laravel and Symfony Mailer provide drivers for sending email via SMTP, Mailgun, Postmark, Amazon SES, and sendmail , allowing you to quickly get started sending mail through a local or cloud based service of your choice.


1 Answers

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.';
}
like image 97
judereid Avatar answered Sep 24 '22 22:09

judereid