Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Halim's avatar
Level 2

How to check if Email has been sent in Laravel 10 API

Im building an API and trying to send welcome email when user register,

I get this message bellow

Method Illuminate\Mail\Mailer::failures does not exist!!!

It seems that Laravel 10 does not have this method which I found on some tutorials, so How to check if the email has been sent or not???

    Mail::to($user->email)->send(new WelcomeEmail());
    if (Mail::failures()) {
        		return response()->Fail('Sorry! Please try again latter');
    }
    else {
       		 return response()->success('Great! Successfully send in your mail');
    }
0 likes
3 replies
LaryAI's avatar
Level 58

In Laravel 10, the Mail::failures() method has been removed. Instead, you can use event listeners to check if an email has been sent or failed. Laravel fires events for various email sending status, such as MessageSending and MessageSent. You can listen for these events to determine if the email was sent successfully.

Here's how you can set up an event listener for the MessageSent event:

First, you need to register the event and listener in your EventServiceProvider:

use Illuminate\Mail\Events\MessageSent;

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    MessageSent::class => [
        'App\Listeners\EmailSentListener',
    ],
];

Next, create the listener class EmailSentListener:

namespace App\Listeners;

use Illuminate\Mail\Events\MessageSent;

class EmailSentListener
{
    /**
     * Handle the event.
     *
     * @param  MessageSent  $event
     * @return void
     */
    public function handle(MessageSent $event)
    {
        // Email was sent successfully
        // You can access the message and other properties via $event->message
    }
}

Now, when you send an email, Laravel will automatically call your listener if the email is sent successfully. If you want to handle failures, you can listen for the MessageFailed event similarly.

Here's how you can send the email and assume it's sent successfully unless an exception is thrown:

try {
    Mail::to($user->email)->send(new WelcomeEmail());
    return response()->json(['message' => 'Great! Successfully sent to your mail'], 200);
} catch (\Exception $e) {
    // Handle the exception or log it
    return response()->json(['message' => 'Sorry! Please try again later'], 500);
}

In this code, if an exception occurs during the sending process, it will be caught, and an appropriate response will be returned. If no exception is thrown, it is assumed that the email was sent successfully.

Remember to import the necessary classes at the top of your file:

use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;

This approach is more reliable in Laravel 10, as it directly handles the success or failure of the email sending process.

1 like
Snapey's avatar

assuming mail is not queued, an exception will be thrown by the mailer if something went wrong in the first leg of sending the message.

Of course there are multiple steps between there and the user seeing it in their mailbox

1 like
amitsolanki24_'s avatar

@halim Hey, check this laracast solution


https://laracasts.com/discuss/channels/laravel/method-illuminatemailmailerfailures-does-not-exist

Please or to participate in this conversation.