terehinis/mandrill-bundle

Symfony Mandrill Bundle

安装次数: 1,903

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 50

类型:symfony-bundle

v1.4 2018-05-03 14:45 UTC

README

Build Status

通过 mandrill.com 发送事务性邮件。此bundle为Symfony2项目提供简单的API。

消息类中的所有设置都代表Mandrill API的属性。请参考他们的API文档以获取详细信息

https://mandrillapp.com/api/docs/messages.html

先决条件

在您能够使用此bundle之前,您必须注册Mandrill。

http://mandrill.com

Mandrill是发送事务性邮件的绝佳方式,并提供详细的先进报告。

Mandrill每天免费发送有限数量的电子邮件,请阅读网站上的定价部分以获取更多信息

http://mandrill.com/pricing/

安装

将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')来更改此设置