charltonsantana / laravel-sendgrid-notification-channel
Laravel 的 SendGrid 通知通道。
v2.0.0
2020-12-09 14:05 UTC
Requires
- php: ^7.1.3
- guzzlehttp/guzzle: ^7.2
- sendgrid/sendgrid: ^7.2
Requires (Dev)
- illuminate/notifications: ~5.7
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-09 22:23:31 UTC
README
先决条件
SendGrid
支持使用预定义模板发送电子邮件,以格式化邮件消息。在您能够发送 SendGrid 邮件通知之前,您需要通过 Composer 安装通知通道。
charltonsantana/laravel-sendgrid-notification-channel
接下来,您需要将一些配置选项添加到您的 config/services.php
配置文件中。您可以将下面的示例配置复制过来开始使用。
'sendgrid' => [
'api_key' => env('SENDGRID_API_KEY'),
],
格式化 SendGrid 邮件通知
您应该在通知类中定义一个 toSendGrid
方法。该方法将接收一个 $notifiable
实体,并应该返回一个 Illuminate\Notifications\Messages\SendGridMessage
实例。
/**
* Get the SendGrid representation of the notification.
*
* @param mixed $notifiable
* @return SendGridMessage
*/
public function toSendGrid($notifiable)
{
return (new SendGridMessage('Your SendGrid template ID'))
->from('test@example.com', 'Example User')
->to('test+test1@example.com', 'Example User1');
}