shehrojkhan786 / laravel-mandrill-notifications-channel
Laravel 8 的 Mandrill 通知通道
1.1.2
2020-07-26 16:54 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.5
- illuminate/notifications: ^5.0 || ^6.0 || ^7.0
- illuminate/support: ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
README
composer require Shehrojkhan786/laravel-mandrill-driver
配置
添加到您的 .env 文件中
MANDRILL_SECRET=YOUR_MANDRILL_API_KEY
在您的 mail.php 文件中
'from' => [
'address' => 'noreply@example.com',
'name' => "From Name"
],
'mandrill' => [
'key' => env('MANDRILL_SECRET', 'SUPER SECRET KEY')
]
用法
基本用法
public function via($notifiable) { return [MandrillChannel::class]; } public function toMandrill($notifiable) { return (new MandrillMessage()) ->subject('Purchase successful') ->addTo($notifiable->email) ->view('mandrill-template-name', [ 'product' => $this->product->toArray(), 'user' => [ 'name' => $notifiable->name, 'phone' => $notifiable->phone ] ]); }
高级
public function toMandrill($notifiable) { return (new MandrillMessage()) ->subject('Purchase successful') ->templateName('mandrill-template-name') ->addTo($notifiable->email) ->addTos(['a@example.com', 'b@example.com']) ->fromName('Customized From') ->fromEmail('custom_from@example.com') ->replyTo('reply@example.com') ->content([ 'product' => $this->product->toArray(), ]); }
可用方法
注意:为了与 Laravel 的 Mail 实现 replyTo 保持一致,您可以通过两个参数传递,第二个参数将被忽略,如果多次调用 replyTo,则只使用第一个参数,其余将被忽略。因为 Mandrill 只允许一个回复的电子邮件地址。
Mandrill 中的用法(动态 Handlebars)
当您在 content 或 view 方法中指定内容时,您可以在 Mandrill 模板中这样编写 handlebars 语法;
嗨 {{user.name}},您已成功购买 {{product.name}}。
Mailchimp 语法
如果您希望使用 Mailchimp 合并标签 而不是动态 Handlebars,则可以将 templateName 方法中的 $mergeLanguage 可选参数设置为 mailchimp。
在 Mailchimp 合并标签中,不支持数组,所以每个标签只接受一个字符串。包括 Mandrill 中的预定关键词在内的完整文档
Mailchimp 示例
public function toMandrill($notifiable) { return (new MandrillMessage()) ->subject('Purchase successful') ->templateName('mandrill-template-name', 'mailchimp') << HERE ->addTo($notifiable->email) ->content([ 'customer_name' => $notifiable->name, 'invoice_link' => 'http://example.com/download/invoice.pdf', ]) }
然后在您的 Mandrill 模板中使用如下:
嗨 *|customer_name|*,您可以从这里下载您的发票 *|invoice_link|*。