orken / mandrill-transport-cakephp3
CakePHP 3+ 的 MandrillTransport 插件
0.97.0
2017-04-20 12:02 UTC
Requires
- php: >=5.5.9
- cakephp/cakephp: >=3.0.0 <4.0.0
This package is not auto-updated.
Last update: 2024-09-14 19:47:35 UTC
README
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式是
composer require orken/mandrill-transport-cakephp3
设置您的 CakePHP 应用程序
在您的 bootstrap.php 文件中。
Plugin::load('MandrillTransport');
在您的 app.php 文件中。
'EmailTransport' => [
'Mandrill' => [
'className' => 'MandrillTransport.Mandrill',
'api_key' => 'YOUR_API_KEY',
'api_key_test' => 'YOUR_TEST_API_KEY',
'from' => 'no-reply@example.com',
'merge_language' => 'handlebars', //optional, default is handlebars
'inline_css' => true, //optional, default is true
],
],
'Email' => [
'mandrill' => [
'transport' => 'Mandrill',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
使用
它可以像常规的 Mail transport 一样在 cakephp 中使用。
如果您想使用 mailchimp/mandrill 的模板,您只需在 viewVars 中添加带有模板名称的 'template_name' 键。并且可选地添加模板中使用的其他变量。
$email = new Email('mandrill');
$email->from(['me@example.com' => 'My Site'])
->to('you@example.com')
->cc('yourcc@exmaple.com') // optional
->bcc('yourbcc@exmaple.com') // optional
->attachments('/path/to/your/file') // optional
->viewVars([
'template_name' => 'your template name at mandrill',
'other_var' => 'values', // all the vars from yout template
...
])
->subject('About') // optional, if missing it takes the template subject
->send('My message');