有人知道吗?有我的代码,以防有人需要看任何东西! <?php命名空间PumpMyLead \ Notifications \ Tenants \ Auth;使用Illuminate \ Bus \ Queueable;使用Illuminate \ Notifications \ Notification;使用Illuminate \ Contracts \ Queue \ ShouldQueue;使用Illuminate \ Notifications \ Messages \ MailMessage;类AccountActivation扩展Notification{使用Queueable;/***创建一个新的通知实例.** @返回无效*/公共功能__construct(){//}/***获取通知的传递渠道.** @param混合$ notifyable* @返回数组*/公共职能通过($ notifiable){返回['mail'];}/***获取通知的邮件表示形式.** @param混合$ notifyable* @return \ Illuminate \ Notifications \ Messages \ MailMessage*/公共功能toMail($ notifiable){返回(新的MailMessage)->主题(我的电子邮件主题")->问候(只是问候")-> line('Line 1')->行(第2行")-> action('CTA想要的','http://www.pumpmylead.com')-> line('Byebye');}} 提前谢谢!解决方案实际上,我发现了两种添加标头的方法.通过邮件通道发送通知时,会触发 Illuminate \ Mail \ Events \ MessageSending 事件.为其添加一个侦听器.在 handle()中,您将获得 Swift_Message 对象.或者在 AppServiceProvider 的 register()方法中使用您自己的方法覆盖 MailChannel 并将标头附加在 send中()方法. $ this-> app-> bind(\ Illuminate \ Notifications \ Channels \ MailChannel :: class,MyMailChannel :: class); Someone knows how to add headers to emails sent through Laravel Notification System?I am not talking about Mailable classes where I can set header through the withSwiftMessage() method!I also would like to keep using the MailMessage once I have a lot of emails built using the line, greetings methods!Any one has any clue?There is my code in case somebody needs to see anything!<?phpnamespace PumpMyLead\Notifications\Tenants\Auth;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Notification;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Notifications\Messages\MailMessage;class AccountActivation extends Notification{ use Queueable; /** * Create a new notification instance. * * @return void */ public function __construct() { // } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['mail']; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return (new MailMessage) ->subject('My email subject') ->greeting('Just a greeting') ->line('Line 1') ->line('Line 2') ->action('CTA wanted', 'http://www.pumpmylead.com') ->line('Byebye'); }}Thanks in advance! 解决方案 Actually I've found 2 ways to append headers.When the notification is sent via mail channel an Illuminate\Mail\Events\MessageSending event is fired.Append a listener to it. In handle() you will get the Swift_Message object.Or in the AppServiceProvider's register() method override the MailChannel with your own and append the header in the send() method.$this->app->bind( \Illuminate\Notifications\Channels\MailChannel::class, MyMailChannel::class); 这篇关于将标头添加到作为Laravel通知发送的电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-23 21:02