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

uzair404's avatar

Unable to get Mesage Id from laravel's Mailable

i am using laravel 11.x, trying to get message-id from the emails that are being sent.. here's my code:

    Mail::send('emails.ExternalTicketMail', [
        'body' => $this->message_body
    ], function ($message) use (&$messageId) {
        $message->to($this->recipient_email)
            ->subject("Ticket #{$this->ticket_id} - Query Follow-up");

        // $messageId = $message->getSymfonySentMessage()->getMessageId();
        // $messageId = $message->getId();
        
    });			

if there is a way to get it from laravel mailable class, it would be better.... any help is appreciated, thanks!

0 likes
5 replies
jdc1898's avatar
Level 21

Unfortunately mail is a fire and wait type of transaction. The SMTP server or API you are using does not return anything. All you can get are transport messages in the logs. If you need delivery stats, you’re limited to if the mail provider offers webhooks or some method of notifying you.

1 like
Glukinho's avatar

In the process of SMTP dialog, there is a chance that receiving server does not provide you a message-id at all, assigning it internally after the message is queued. Some servers send it on session closing, some don't, so there is no standard and reliable way to retrieve it from Laravel mailable.

Why do you need it? This is internal id, it has meaning only inside a mail server, how you plan to use it?

1 like
uzair404's avatar

got it, so i can not get it, this way, actually i saw laracast post retrieving message id, this way... as for why i need it is basically i am creating an email thread system....but now i think even if i dont have it, its not big of a problem, or can it be?

thanks for the replies,

Glukinho's avatar

It depends on what you call "thread system" and what you want to achieve.

In general, mail servers track threads or conversations (a bunch of emails sent/received in reply to one another) using Message-Id, In-Reply-To, Original-Message-ID headers and Subject field. Each mail system has it's own logic how to do it.

If you need similar logic, you may rely on Subject with some ID within: [ID-456] actual subject where 456 is an identifier of conversation or ticket in your app. What happens if a user clears subject on reply? Well, it breaks the logic. That's why email isn't reliable for this purpose.

1 like
uzair404's avatar

Oh! thank you, actually i got it working for now, using these headers:

References: [email protected] [email protected]
X-Ticket-ID: 3
In-Reply-To: [email protected]

also i am saving the message-id, with MessageSent Event,

if i need any more assistance on this, i'll surely reach out to you...again Thank You Very Much!

Please or to participate in this conversation.