Add default mail headers in Laravel 5.2

2020-05-02 10:00发布

I need to send a mail header "x-mailgun-native-send: true" to all my mails so they wont get rejected by receivers.

Is it possible to set default mail headers in Laravel? I know I can add headers with every mail by adding this:

$m->getHeaders()->addTextHeader('x-mailgun-native-send', true);

Thanks

1条回答
做个烂人
2楼-- · 2020-05-02 10:25

I found at Laravel will fire an event right before sending an email: https://laravel.com/docs/5.3/mail#events You can listen for this event and add your headers in the event listeners handle method.

public function handle(MessageSending $event)
{
    $headers = $event->message->getHeaders();
    $headers->addTextHeader('x-mailgun-native-send', true);
}
查看更多
登录 后发表回答