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

amitsolanki24_'s avatar

How can I filter outgoing mails in laravel 11?

Hey all, I'm facing a problem can anyone help me please.

How can I filter outgoing mails in laravel 11 on staging server to check if emails exists in (to, cc and bcc) then send that email to staging email.

0 likes
6 replies
Braunson's avatar

Why not check before sending the outgoing mail? How are you dispatching emails?

1 like
amitsolanki24_'s avatar

I'm dispatching emails using mailable class.

Why not check before sending the outgoing mail?

Mail::to(filterEmail($email))->send(new newMail());

If I create filterEmail function So I will have to use this every time, I think, that's not right.

Jsanwo64's avatar

@amitsolanki24_ To avoid repeating the filterEmail function every time you send an email, you can achieve the desired filtering by creating a custom mailer

Jsanwo64's avatar

To filter outgoing emails in Laravel 11, particularly on a staging server, employ a custom mailer or middleware to intercept and alter email recipients before they are sent.

  1. Create a Custom Mailer
  2. Configure the Custom Mailer
  3. Intercept Emails in the Custom Mailer
1 like

Please or to participate in this conversation.