Ben Borgers

How to set a Return-Path header for Laravel mail

January 27, 2021

The Return-Path header in an email defines which email address should receive bounces and complaints (such as getting marked as spam). It's useful to set this header so you can monitor how many complaints you're getting, and which emails are bouncing.

You can set this header in a Laravel Mailable using the withSwiftMessage() method:

public function build()
{
    $this->withSwiftMessage(function ($message) {
        $message->getHeaders()
                ->addTextHeader('Return-Path', '[email protected]');
    });

    return $this
        ->view('some.view');
        // the rest of the normal mailable methods for from, subject, etc
}

Now, this email will have the Return-Path header defined, and receiving email clients will send a notification email to that address if the email bounces or is marked as spam.

More blog posts

Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iā€™m working on!

Twitter ↗ RSS feed ↗