a2design-company / mandrill-cakephp-plugin
Mandrill CakePHP 插件
1.0.1
2015-05-12 12:29 UTC
Requires
- php: >=5.3.0
- lib-curl: *
- composer/installers: *
This package is not auto-updated.
Last update: 2024-09-14 14:50:26 UTC
README
用法
此插件使用 CakeEmail 类,几乎具有相同的功能。
基本示例
App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail('mandrill'); $email->to('recipient@domain.com'); $email->subject('Test email via Mandrill'); $email->send('Message');
更高级的示例
App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail(array( 'transport' => 'Mandrill.Mandrill', 'from' => 'from@example.com', 'fromName' => 'FromName', 'timeout' => 30, 'api_key' => 'YOUR_API_KEY', 'emailFormat' => 'both', )); $viewVars = array( 'var1' => 'some1', 'var2' => 'some2' ); $to = array( 'to1@example.com', 'to2@example.com', ); $email->addHeaders(array( 'tags' => array('test',), 'subAccount' => 'YOUR_SUBACCOUNT', 'preserve_recipients' => false, 'global_merge_vars' => array( array( 'name' => 'date', 'content' => date('Y-m-d'), ), ), 'merge_vars' => array( array( 'rcpt' => 'to1@example.com', 'vars' => array( array( 'name' => 'email', 'content' => 'to1@example.com' ), array( 'name' => 'name', 'content' => 'to1Name' ), ) ), array( 'rcpt' => 'to2@example.com', 'vars' => array( array( 'name' => 'email', 'content' => 'to2@example.com' ), array( 'name' => 'name', 'content' => 'to2Name' ), ) ), ), )); $email->addAttachments(array( 'example.pdf' => array( 'file' => APP . '/webroot/files/readme.pdf', 'mimetype' => 'application/pdf', ), 'logo.png' => array( 'file' => APP . '/webroot/img/logo.png', 'mimetype' => 'image/png', // 'contentId' => 'headerLogo', // Uncomment this line if you want use inline image )); $email->template('test', 'default'); $email->viewVars($viewVars); $email->to($to); $email->subject('Mandrill CakePHP Plugin Test'); $email->send();
电子邮件模板的一部分
<p>Global vars example. Here the current date: *|date|*</p> <p>Email sent for *|name|* (*|email|*)</p>
有关子账户的详细信息,请参阅这里。
所有参数的语法与默认的 CakeEmail 类 相同。
安装
您可以将插件克隆到您的项目中
cd path/to/app/Plugin
git clone git@github.com:a2design-company/Mandrill-CakePHP-plugin.git Mandrill
您还可以使用 composer 安装此插件。只需在您的 composer.json 中添加新要求即可
"require": {
...,
"a2design-company/mandrill-cakephp-plugin": "*"
},
在 app/Config/bootstrap.php 中启动插件
CakePlugin::load('Mandrill');
配置
创建文件 app/Config/email.php,其中包含 EmailConfig 类。
<?php class EmailConfig { public $mandrill = array( 'transport' => 'Mandrill.Mandrill', 'from' => 'from@example.com', 'fromName' => 'FromName', 'timeout' => 30, 'api_key' => 'YOUR_API_KEY', 'emailFormat' => 'both', ); }
要求
CakePHP 2.0+
许可证
许可协议为 MIT 许可
由 A2 Design Inc. 开发