squibby
2 years ago
278
6
Laravel

How to add custom headers to Notification emails?

Posted 2 years ago by squibby

Since upgrading to Laravel 5.4 I have been making use of notifications. I send some emails via mailgun and previously added a custom header so I could receive webhooks from mailgun and track mail delivery etc.

I would do something like below:

Mail::send('emails.broadcast', array('recipient' => $this->recipient , 'broadcast' => $this->broadcast), function($message) use ($data) {
    $message->getHeaders()->addTextHeader('recipient_token', $data['token']);
    $message->to($data['email']);
    $message->subject($data['title']);
});

So.. how can I add the custom header I need to send in the email? I don't want to send the header in all emails, just some specific emails from my app.

Thanks.

Please sign in or create an account to participate in this conversation.