将标头添加到Laravel 5.4通知系统发送的电子邮件中

Gus*_*lli 5 php email notifications swiftmailer laravel-5

有人知道如何将标题添加到通过Laravel Notification System发送的电子邮件中吗?

我不是在谈论Mailable类,我可以通过该withSwiftMessage()方法设置标题!

我也想使用,以保持MailMessage一次我有很多内置的电子邮件的使用line,greetings方法!

任何人都有任何线索?

有我的代码以防有人需要看到任何东西!

<?php

namespace 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');
    }
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Ked*_*nor 6

实际上我找到了两种方法来追加标题.

通过邮件通道发送通知时Illuminate\Mail\Events\MessageSending会触发事件.

为它添加一个监听器.在handle()您将得到Swift_Message对象.

或者在方法中使用您自己AppServiceProviderregister()方法覆盖,MailChannel并在send()方法中附加标题.

$this->app->bind(
    \Illuminate\Notifications\Channels\MailChannel::class,
    MyMailChannel::class
);
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,事件侦听器看起来是添加标头并继续使用简单通知的最简单方法 (2认同)