weblee / mandrill
Laravel 5 Mandrill API 包装器
dev-master
2016-04-05 10:44 UTC
Requires
- php: >=5.3.0
- mandrill/mandrill: 1.0.*
Requires (Dev)
- phpspec/phpspec: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 15:58:03 UTC
README
为 Laravel 5 提供简单的 Mandrill API 包装器。
此包允许您完全与 Mandrill API 交互,例如,通过模板发送电子邮件、获取用户数据、将电子邮件添加到黑名单等...
要求
Laravel 5 及 PHP 5.3 及以上版本。
文档
安装
像往常一样,通过 Composer 安装 Commander。
"require": {
"weblee/mandrill": "dev-master"
}
接下来,更新 config/services.php
文件,使用您的 Mandrill API 密钥。您最好使用 Laravel env 文件来存储您的密钥。
'mandrill' => [ 'secret' => env('MANDRILL_KEY'), ],
现在,您可以注册服务提供者和外观(如果需要的话)config/app.php
。
'providers' => [ ...... Weblee\Mandrill\MandrillServiceProvider::class, ], 'aliases' => [ ...... 'MandrillMail' => Weblee\Mandrill\MandrillFacade::class ]
用法
将服务注入到您的构造函数或类方法中,或使用提供的外观。
示例
<?php namespace App; use Weblee\Mandrill\Mail; class SendMyMail{ private $mandrill; /** * Via construct injection * */ public function __construct(Mail $mandrill) { $this->mandrill = $mandrill; } public function sendTemplate($data) { $this->mandrill->messages()->sendTemplate($data) } // ----- OR ------- /** * Via method injection * */ public function sendMail(Mail $mandrill, $data) { $mandrill->messages()->sendTemplate($data) } // ----- OR ------- /** * Via the Facade * */ public function sendMailByFacade($data) { \MandrillMail::messages()->sendTemplate($data); } }
只需遵循 Mandrill 文档中关于您可以执行的操作和数据提供的内容即可。