daily/hipaway-mandrill-bundle

此包的最新版本(v0.12)没有可用的许可信息。

Symfony HipMandrillBundle

安装: 63

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 0

开放问题: 0

类型:symfony-bundle

v0.12 2013-07-11 20:34 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:21:29 UTC


README

[构建状态] (http://travis-ci.org/Hipaway-Travel/HipMandrillBundle)

通过 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.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>');

    }

}