Laravel Add List-Unsubscribe Header to Mail (e.g. Mailgun & Hotmail)

When using e.g. Mailgun for Laravel Mail, sometimes it could happen that mails end up in spamfolders. One of the reasons for this is that default a List-Unsubscribe header is not set. That is a link that you send to your unsubscribe mail.

Add this code in you mail closure:

$message->getSwiftMessage()
                    ->getHeaders()
                    ->addTextHeader('List-Unsubscribe', '<' . action('NewsletterController@delete', 'YOURUSERIDORTOKEN') . '>');

So then it becomes like:

\Mail::send(['emails.newsletter-activate.html', 'emails.newsletter-activate.text'], $toMailView, function ($message) use ($email, $subject) {
            $message->subject($subject);
            $message->to($email);
            $message->getSwiftMessage()
                    ->getHeaders()
                    ->addTextHeader('List-Unsubscribe', '<' . action('NewsletterController@delete', 'YOURUSERIDORTOKEN') . '>');
        });

This seems to work in Hotmail. In our cases it removed the case where Hotmail moved our Mailgun e-mails to the SPAM-box.

Are mails completely blocked by your ISP? Ask MailGun for a new IP

We also had a case where Mailgun assigned us an IP that was blocked by Hotmail. Send a support query to Mailgun and ask for a new IP-address. With above tips Mailgun delivered our e-mails correctly in the mailbox.

Leave a Comment

Your email address will not be published. Required fields are marked *

en_USEnglish
Scroll to Top