astonishdesign / mandrill-bundle
Symfony HipMandrillBundle 分支
v1.0.3
2015-01-09 08:36 UTC
Requires
- mandrill/mandrill: 1.*
- symfony/config: >=2.1,<2.7-dev
- symfony/http-foundation: >=2.1,<2.7-dev
This package is not auto-updated.
Last update: 2024-09-28 16:38:37 UTC
README
通过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
在kernel中启用捆绑包
<?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 disable_delivery: true # useful for dev/test environment. Default value is 'false' default: sender: info@example.com sender_name: John Doe subaccount: Project # Optionally define a subaccount to use
要覆盖FOSUserBundle的Mailer
# config.yml fos_user: # ... service: mailer: hip_mandrill.fosuser.mailer
现在您已准备就绪,发送您的第一封事务性邮件
使用
简单控制器示例
<?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>') ->setSubaccount('Project'); $result = $dispatcher->send($message); return new Response('<pre>' . print_r($result, true) . '</pre>'); } }