xstyled / mandrill-bundle
Symfony HipMandrillBundle
dev-master
2013-11-06 09:48 UTC
Requires
- mandrill/mandrill: 1.*
- symfony/config: >=2.1,<2.5-dev
- symfony/http-foundation: >=2.1,<2.5-dev
This package is auto-updated.
Last update: 2024-09-12 01:27:13 UTC
README
[] (http://travis-ci.org/Hipaway-Travel/HipMandrillBundle)
通过mandrill.com发送事务性邮件。此捆绑包为Symfony2项目提供简单的API。
消息类中的所有设置都代表Mandrill API的属性。请参阅他们的API文档以获取详细信息
https://mandrillapp.com/api/docs/messages.html
先决条件
在您能够使用此捆绑包之前,您必须注册Mandrill。
Mandrill是一种发送事务性邮件的好方法,并提供了详细的先进报告。
Mandrill每天发送有限数量的免费邮件,请参阅网站上的定价部分获取更多信息
安装
将捆绑包添加到您的composer.json文件中
# composer.json { "require": { "hipaway-travel/mandrill-bundle": "dev-master", } }
运行composer install
php ./composer.phar install
在内核中启用捆绑包
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Hip\MandrillBundle\HipMandrillBundle(),
);
}
配置
将配置添加到config.yml文件中。
登录到Mandrill,然后转到“设置”->“SMTP和API凭据”。创建一个API密钥并在您的Symfony2配置中使用它。
# config.yml hip_mandrill: api_key: xxxxx default: sender: info@example.com sender_name: John Doe
现在您已准备就绪,发送您的第一封事务性邮件
使用
简单控制器示例
<?php // src/Hip/ExampleBundle/Controller/ExampleController.php namespace Hip\ExampleBundle\Controller; use Symfony\Component\HttpFoundation\Response; use Hip\MandrillBundle\Message; use Hip\MandrillBundle\Dispatcher; class ExampleController { public function indexAction() { $dispatcher = $this->get('hip_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>'); $result = $dispatcher->send($message); return new Response('<pre>' . print_r($result, true) . '</pre>'); } }