slot/mandrill-bundle

Symfony Mandrill Bundle

安装次数: 1,432,794

依赖项: 1

建议者: 0

安全性: 0

星标: 66

关注者: 4

分支: 50

开放问题: 7

类型:symfony-bundle

v1.2 2021-01-06 06:56 UTC

README

Build Status

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

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

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

先决条件

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

http://mandrill.com

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

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

http://mandrill.com/pricing/

安装

通过composer

composer require slot/mandrill-bundle

在kernel中启用此包

<?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

默认情况下,此包将假设合并语言为'mailchimp'。您可以使用$message->setMergeLanguage('handlebars')更改此设置