ffreitas-br / mandrill-bundle
Symfony MandrillBundle
v2.0.0
2015-03-27 19:05 UTC
Requires
- mandrill/mandrill: 1.*
- symfony/symfony: 2.5.*@stable
Requires (Dev)
- phpunit/phpunit: 4.1.*@stable
This package is not auto-updated.
Last update: 2024-09-28 17:54:28 UTC
README
通过mandrill.com发送交易邮件。此组件为Symfony2项目提供了一个简单的API。
消息类内的所有设置都代表Mandrill API的属性。请参考他们的API文档以获取详细信息
https://mandrillapp.com/api/docs/messages.html
先决条件
在您能够使用此组件之前,您必须在Mandrill上注册。
Mandrill是一种发送交易邮件的好方法,并提供详细的先进报告。
Mandrill每天提供有限的免费电子邮件,请阅读网站上的定价部分以获取更多信息
安装
将组件添加到composer.json
# composer.json { "require": { "ffreitas-br/mandrill-bundle": "1.*", } }
运行composer install
php ./composer.phar install
在kernel中启用组件
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new FFreitasBr\MandrillBundle\MandrillBundle(),
);
}
配置
将配置添加到config.yml。
登录到Mandrill,然后转到“设置” -> “SMTP和API凭据”。创建一个API密钥并将其用于您的Symfony2配置。
# config.yml 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 proxy: use: true # when you are behing a proxy. Default value is 'false' host: example.com port: 80 user: john password: doe123
现在您已经准备就绪,发送您的第一封交易邮件
用法
简单控制器示例
<?php // src/FFreitasBr/ExampleBundle/Controller/ExampleController.php namespace FFreitasBr\ExampleBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; use FFreitasBr\MandrillBundle\Message; use FFreitasBr\MandrillBundle\Dispatcher; class ExampleController extends Controller { public function indexAction() { $dispatcher = $this->get('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>'); } }