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

morceaudebois's avatar

MessageSent mail event is never triggered

Hi!

I'm trying to use the MessageSent event in Laravel 11. I created a simple EventListener like this:

<?php

namespace App\Listeners;

use App\Events\MessageSent;
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class LogEmails {
    /**
     * Create the event listener.
     */
    public function __construct() {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(MessageSent $event): void {
        Log::info("Message sent!");
    }
}

I send emails like this:

Mail::to($booking->email)->send(new BookingNotification($booking, $booking->status));

The Mailable is sending emails and doesn't have any issue, yet MessageSent never seems to get triggered even if it appears when I do php artisan event:list.

Any idea what could be going on? Thank you 😊

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

What is the App\Events\MessageSent class? Since it is in the App namespace, it appears to be something you have implemented; so how does the framework dispatch it?

We have a Illuminate\Mail\Events\MessageSent class that the framework's Mailer class will dispatch whenever it sends a mail; perhaps your Listener should be using that instead?

<?php

namespace App\Listeners;

use Illuminate\Mail\Events\MessageSent; // import correct Event class!
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class LogEmails {
    /**
     * Create the event listener.
     */
    public function __construct() {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(MessageSent $event): void {
        Log::info("Message sent!");
    }
}
1 like
morceaudebois's avatar

@tykus Yes, this works! Thank you so much!

I had created the listener with this command: php artisan make:listener LogEmails --event=MessageSent

I thought the import was correct but I now understand my mistake 😅

1 like

Please or to participate in this conversation.