terehinis / mandrill-bundle
Symfony Mandrill Bundle
v1.4
2018-05-03 14:45 UTC
Requires
- mandrill/mandrill: 1.*
- symfony/config: >=2.8
- symfony/http-foundation: >=2.8
Requires (Dev)
- phpunit/phpunit: >=5.7.21
- symfony/debug: >=2.8
- symfony/phpunit-bridge: >=2.8
README
通过 mandrill.com 发送事务性邮件。此bundle为Symfony2项目提供简单的API。
消息类中的所有设置都代表Mandrill API的属性。请参考他们的API文档以获取详细信息
https://mandrillapp.com/api/docs/messages.html
先决条件
在您能够使用此bundle之前,您必须注册Mandrill。
Mandrill是发送事务性邮件的绝佳方式,并提供详细的先进报告。
Mandrill每天免费发送有限数量的电子邮件,请阅读网站上的定价部分以获取更多信息
安装
将bundle添加到composer.json文件中
# composer.json { "require": { "slot/mandrill-bundle": "dev-master", } }
运行composer install
php ./composer.phar install
在kernel中启用bundle
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Slot\MandrillBundle\SlotMandrillBundle(),
);
}
配置
将配置添加到config.yml文件中。
登录Mandrill并转到“设置” -> “SMTP和API凭据”。创建一个API密钥并在您的Symfony2配置中使用它。
# config.yml slot_mandrill: api_key: xxxxx disable_delivery: true # useful for dev/test environment. Default value is 'false' # debug: passed to \Mandrill causing it to output curl requests. Useful to see output # from CLI script. Default value is 'false' debug: true default: sender: info@example.com sender_name: John Doe # Optionally define a sender name (from name) subaccount: Project # Optionally define a subaccount to use proxy: use: true # when you are behing a proxy. Default value is 'false' host: example.com port: 80 user: john password: doe123
现在您已准备就绪,发送您的第一封事务性邮件
使用
简单的控制器示例
<?php // src/Slot/ExampleBundle/Controller/ExampleController.php namespace Slot\ExampleBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; use Slot\MandrillBundle\Message; use Slot\MandrillBundle\Dispatcher; class ExampleController extends Controller { public function indexAction() { $dispatcher = $this->get('slot_mandrill.dispatcher'); $message = new Message(); $message ->setFromEmail('mail@example.com') ->setFromName('Customer Care') ->addTo('max.customer@email.com') ->setSubject('Some Subject') ->setHtml('<html><body><h1>Some Content</h1></body></html>') ->setSubaccount('Project'); $result = $dispatcher->send($message); return new Response('<pre>' . print_r($result, true) . '</pre>'); } }
使用Handlebars
默认情况下,bundle将假设合并语言是'mailchimp'。您可以使用$message->setMergeLanguage('handlebars')
来更改此设置