yieldstudio / laravel-mailjet-notifier
使用 Laravel 通知器轻松发送 Mailjet 事务性电子邮件和短信。
0.0.9
2023-09-07 08:50 UTC
Requires
- php: ^8.0
- illuminate/database: ^9|^10
- illuminate/support: ^9|^10
- mailjet/mailjet-apiv3-php: ^1.5
Requires (Dev)
- ciareis/bypass: ^1.0
- friendsofphp/php-cs-fixer: ^3.8
- orchestra/testbench: 7.*|8.*
- pestphp/pest: ^1.21
- phpunit/phpunit: ^9.1
README
使用 Laravel 通知器轻松发送 Mailjet 事务性电子邮件和短信。
如果您只是想找一个 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 install
和 composer test
。
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全性
如果您发现有关安全性的错误,请通过邮件 contact@yieldstudio.fr 而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。