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.';
}
You can check if an email is valid or not in Laravel using the validate method by passing in the validation rules.
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.
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.';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With