yieldstudio/laravel-mailjet-notifier

使用 Laravel 通知器轻松发送 Mailjet 事务性电子邮件和短信。

0.0.9 2023-09-07 08:50 UTC

This package is auto-updated.

Last update: 2024-09-20 07:47:08 UTC


README

使用 Laravel 通知器轻松发送 Mailjet 事务性电子邮件和短信。

Latest Version GitHub Workflow Status Total Downloads

如果您只是想找一个 Mailjet 邮件传输,请查看 mailjet/laravel-mailjet

主版本零(0.y.z)用于初始开发。任何内容都可能随时更改。公共 API 不应被视为稳定。

安装

composer require yieldstudio/laravel-mailjet-notifier

配置

只需定义这些环境变量

MAILJET_APIKEY=
MAILJET_APISECRET=
MAILJET_SMSTOKEN=
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
MAILJET_SMS_SENDER=
MAILJET_DRY=true|false

确保 MAIL_FROM_ADDRESS 是 Mailjet 上的认证电子邮件,否则您的邮件将无法通过 Mailjet API 发送。

MAILJET_SMS_SENDER 的长度应在 3 到 11 个字符之间,只允许字母数字字符。

当启用干燥模式时,不会调用 Mailjet API。

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="YieldStudio\LaravelMailjetNotifier\MailjetNotifierServiceProvider" --tag="config"

使用方法

发送电子邮件

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use YieldStudio\LaravelMailjetNotifier\MailjetEmailChannel;

class OrderConfirmation extends Notification
{
    public function via(): array
    {
        return [MailjetEmailChannel::class];
    }

    public function toMailjetEmail($notifiable): MailjetEmailMessage
    {
        return (new MailjetEmailMessage())
            ->templateId(999999) // Replace with your template ID
            ->to($notifiable->firstname, $notifiable->email)
            ->variable('firstname', $notifiable->firstname)
            ->variable('order_ref', 'N°0000001');
    }
}

发送短信

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification
;use YieldStudio\LaravelMailjetNotifier\MailjetSmsChannel;
use YieldStudio\LaravelMailjetNotifier\MailjetSmsMessage;

class ResetPassword extends Notification
{
    public function __construct(protected string $code)
    {
    }

    public function via()
    {
        return [MailjetSmsChannel::class];
    }

    public function toMailjetSms($notifiable): MailjetSmsMessage
    {
        return (new MailjetSmsMessage())
            ->to($notifiable->phone)
            ->text(__('This is your reset code :code', ['code' => $this->code]));
    }
}

单元测试

要运行测试,只需运行 composer installcomposer test

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

贡献

有关详细信息,请参阅 CONTRIBUTING

安全性

如果您发现有关安全性的错误,请通过邮件 contact@yieldstudio.fr 而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件