2017-04-19 49 views
2

有人知道如何为通过Laravel Notification System发送的电子邮件添加标题?向Laravel 5.4通知系统发送的电子邮件添加标题

我不是在谈论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'); 
    } 
} 

在此先感谢!

回答

3

其实我找到了2种追加标题的方法。

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

追加一个侦听器给它。在handle()中,您将获得Swift_Message对象。

或在AppServiceProviderregister()方法覆盖您自己的MailChannel并在send()方法中追加标头。

$this->app->bind(
    \Illuminate\Notifications\Channels\MailChannel::class, 
    MyMailChannel::class 
); 
+1

谢谢,事件监听器看起来像添加标题并继续使用简单通知的最简单方法 – chifliiiii

相关问题