How to add headers to email in Laravel 5.1

前端 未结 3 609
遇见更好的自我
遇见更好的自我 2021-02-13 00:21

Is there a way to add default headers to all emails in Laravel 5.1? I want all emails to be sent with the following header:

x-mailgun-native-send: true
         


        
3条回答
  •  不思量自难忘°
    2021-02-13 01:00

    Slight modification to @maxim-lanin's answer. You can use it like this, fluently.

    \Mail::send('email.view', ['user' => $user], function ($message) use ($user) {
        $message->to($user->email, $user->name)
            ->subject('your message')
            ->getSwiftMessage()
            ->getHeaders()
            ->addTextHeader('x-mailgun-native-send', 'true');
    });
    

提交回复
热议问题