addgod/laravel-mandrill-template
最新稳定版本:v2.0.1
Composer 安装命令:
composer require addgod/laravel-mandrill-template
包简介
Using Mandrill templates in Laravel.
README 文档
README
A way to send mail via mandrills template system.
Installation
Requirements
- PHP 7.2
- Laravel 6
You can install the package via composer:
composer require addgod/laravel-mandrill-template
To publish the config file run:
php artisan vendor:publish --provider="Addgod\MandrillTemplate\MandrillTemplateServiceProvider"
Usage
Add your mandrill secret key to your .env file.
MANDRILL_SECRET="YOUR SECRET KEY"
Sending mail
use Addgod\MandrillTemplate\Mandrill\Message; use Addgod\MandrillTemplate\Mandrill\Template; use Addgod\MandrillTemplate\Mandrill\Recipient; use Addgod\MandrillTemplate\Mandrill\Attachment; use Addgod\MandrillTemplate\Mandrill\Recipient\Type; use Addgod\MandrillTemplate\MandrillTemplateFacade;
$template = new Template('template-name'); $message = new Message(); $message ->setSubject('Subjct') ->setFromEmail('from@example.com') ->setFromName('Example Name') ->setMergeVars(['greeting' => 'Hello to you']); $message->addRecipient(new Recipient('to@example.com', 'Example Name', Type::TO)); $message->addAttachment(Attachment::createFromFile($file, 'name_of_file'); MandrillTemplateFacade::send($template, $message);
Via notifications
Create a new notification
php artisan make:notification WelcomeNotification
Set via to MandrillTemplateChannel:
use Addgod\MandrillTemplate\MandrillTemplateChannel;
/** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [MandrillTemplateChannel::class]; }
Implement toMandrillTemplate method and prepare your template:
use Addgod\MandrillTemplate\MandrillTemplateMessage;
public function toMandrillTemplate($notifiable) { return (new MandrillTemplateMessage) ->template('notification') ->from('from@example.com', 'Example dot com') ->to('to@example.com', 'Frank Kornell') // This is an extra to, since the notifiable is also used. ->cc('cc@example.com', 'Charlott Kornell') ->bcc('bcc@example.com', 'Mr admin Dude') ->greeting('Hello there'), ->line('The introduction to the notification.') ->action('Notification Action', url('/')) ->line('Thank you for using our application!') ->salutation('Regards from us.') ->attach($file, 'name_of_file); }
统计信息
- 总下载量: 25.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-05