a2design-company / sendgrid-webapi-cakephp-plugin
Sendgrid WebAPI CakePHP 插件
v1.0.1
2016-04-11 01:55 UTC
Requires
- php: >=5.3.0
- composer/installers: *
This package is not auto-updated.
Last update: 2024-09-14 10:51:52 UTC
README
用法
此插件使用 CakeEmail 类,用法几乎相同。
基本示例
App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail('sendGrid'); $email->to('recipient@domain.com'); $email->subject('Test email via SendGrid'); $email->send('Message');
更高级的示例
App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail('sendGrid'); $email->template('default', 'default'); $email->emailFormat('html'); $email->viewVars(array('name' => 'Your Name')); $email->to(array('recipient1@domain.com' => 'Recipient1', 'recipient2@domain.com' => 'Recipient2')); $email->subject('Test email via SendGrid'); $email->addHeaders(array('X-Tag' => 'my tag')); $email->attachments(array( 'cake.icon.png' => array( 'file' => WWW_ROOT . 'img' . DS . 'cake.icon.png' ) )); $email->send();
所有参数的语法与默认的 CakeEmail 类 相同
安装
您可以将插件克隆到您的项目中
cd path/to/app/Plugin
git clone git@github.com:a2design-company/sendgrid-webapi-cakephp-plugin.git Sendgrid
在 app/Config/bootstrap.php 中启动插件
CakePlugin::load('Sendgrid');
配置
使用类 EmailConfig 创建文件 app/Config/email.php
<?php class EmailConfig { public $sendGrid = array( 'transport' => 'Sendgrid.Sendgrid', 'from' => 'you-email@sendgrid.com', 'fromName' => 'You name', 'timeout' => 30, 'username' => 'username@sendgrid.com', //SendGrid username 'password' => 'password', //SendGrid password 'client' => null, 'log' => false, 'emailFormat' => 'both', 'category' => 'transaction', //default SendGrid category for emails 'count' => 200, //count of email to send in one API call, max 500, default 500 ); }
要求
CakePHP 2.0+
许可证
许可协议为 The MIT License
由 A2 Design Inc. 开发