Reputation: 12608
I am sending email via Mailgun from a Laravel 5.5 app like this...
Mail::send('emails.sendmessage', $data, function($message) use ($data) {
$message->to($data['email']);
$message->from('[email protected]', 'Ueer');
$message->subject('Sample Email');
});
/* Return Success Response */
return Response::json(array(
'error' => false,
'status_code' => 200,
'response' => 'success',
));
How can I catch Mailgun errors with this code? Sometimes MailGun returns an error message and I would like to return a different response if this happens
Upvotes: 2
Views: 1988
Reputation: 118
You can take a look at this question : Laravel 5 - How Do You Catch an Mail::send() Error?
Adding a try and catch should do the trick.
If you don't want to add a try/catch for whatever reason, I would recommend you to validate beforehand every parameters susceptile of throwing an error from Mail::send
Upvotes: 3