hulsia/laravel-brevo-notifier

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

v1.0.0 2024-07-04 11:44 UTC

This package is not auto-updated.

Last update: 2024-09-27 11:15:56 UTC


README

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

Latest Version GitHub Workflow Status Total Downloads

安装

composer require hulsia/laravel-brevo-notifier

配置

只需定义这些环境变量

BREVO_KEY=
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
BREVO_SMS_SENDER=

请确保MAIL_FROM_ADDRESS是Brevo上的认证电子邮件。

BREVO_SMS_SENDER仅限于11个字母数字字符和15个数字字符。

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

php artisan vendor:publish --provider="YieldStudio\LaravelBrevoNotifier\BrevoNotifierServiceProvider" --tag="config"

使用方法

发送邮件

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use YieldStudio\LaravelBrevoNotifier\BrevoEmailChannel;
use YieldStudio\LaravelBrevoNotifier\BrevoEmailMessage;

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

    public function toBrevoEmail($notifiable): BrevoEmailMessage
    {
        return (new BrevoEmailMessage())
            ->templateId(1)
            ->to($notifiable->firstname, $notifiable->email)
            ->params(['order_ref' => 'N°0000001']);
    }
}

发送短信

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification
use YieldStudio\LaravelBrevoNotifier\BrevoSmsChannel;
use YieldStudio\LaravelBrevoNotifier\BrevoSmsMessage;

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

    public function toBrevoSms($notifiable): BrevoSmsMessage
    {
        return (new BrevoSmsMessage())
            ->from('YIELD')
            ->to('+33626631711')
            ->content('Your order is confirmed.');
    }
}

单元测试

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

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全

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

致谢

许可

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