numesia/

mailjet

Mailjet 通知驱动程序

1.4 2024-07-29 14:42 UTC

This package is auto-updated.

Last update: 2024-09-29 14:59:13 UTC


README

此包简化了在 Laravel 5.5+、6.x 和 7.x 中使用 Mailjet 发送通知的过程。

内容

先决条件

配置 https://github.com/mailjet/laravel-mailjet

安装

您可以通过 composer 安装此包

composer require numesia/mailjet

添加 Mailjet 提供商

'providers' => [
    ...
    Numesia\Mailjet\MailjetServiceProvider::class,
    ...
]

使用

现在您可以在通知内的 via() 方法中使用此通道

use Numesia\Mailjet\MailjetChannel;
use Numesia\Mailjet\MailjetMessage;
use Illuminate\Notifications\Notification;

class ProjectCreated extends Notification
{
    public function via($notifiable)
    {
        return [MailjetChannel::class]; // or 'mailjet'
    }

    public function toMailjet($notifiable)
    {
        return (new MailjetMessage)
            ->sender("sender@email.com")
            ->name("Sender Name")
            ->subject("My Subject")
            ->content("My Html Content"); // or ->view("view:location", [])
    }
}

为了让通知知道使用哪个电子邮件,将 routeNotificationForMailjet 方法添加到您的 Notifiable 模型中。

此方法需要返回一个电子邮件地址。

public function routeNotificationForMailjet(Notification $notification)
{
    return $this->email;
}

测试

$ composer test