owenoj/laravel-mailjet-notifier

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

dev-main 2024-09-02 15:30 UTC

This package is auto-updated.

Last update: 2024-09-02 15:32:41 UTC


README

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

Latest Version GitHub Workflow Status Total Downloads

如果你只是在寻找Mailjet邮件传输,请查看mailjet/laravel-mailjet

主版本0(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以获取详细信息。

安全性

如果你发现了一个关于安全性的bug,请通过contact@yieldstudio.fr发送邮件,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。