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)
提前致谢!
实际上我找到了两种方法来追加标题.
通过邮件通道发送通知时Illuminate\Mail\Events\MessageSending会触发事件.
为它添加一个监听器.在handle()您将得到Swift_Message对象.
或者在方法中使用您自己AppServiceProvider的register()方法覆盖,MailChannel并在send()方法中附加标题.
$this->app->bind(
\Illuminate\Notifications\Channels\MailChannel::class,
MyMailChannel::class
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2256 次 |
| 最近记录: |