2017-04-19 89 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

相關問題