hamaryuginh/mandrillbundle

This package is abandoned and no longer maintained. No replacement package was suggested.

A Symfony2 Bundle for Mandrill

dev-master / 0.4.0.x-dev 2014-11-21 19:39 UTC

README

Work still in progress

A Symfony2 Bundle for Mandrill

This project is a fork of https://github.com/Hipaway-Travel/HipMandrillBundle

SensioLabsInsight

Prerequisites

Before you're able to use this bundle you must sign up with Mandrill.

http://mandrill.com

Mandrill is a great way to send your transactional emails and provides detailed advances reports.

Mandrill is free for limited number of email per day, please read through pricing section on the website for more information:

http://mandrill.com/pricing/

Installation

Add the bundle to your composer.json

{
    "require": {
        "...",
        "hamaryuginh/mandrillbundle": "dev-master"
    }
}

Run composer install

php composer.phar install

Enable the bundle in the kernel

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Hamaryuginh\MandrillBundle\HamaryuginhMandrillBundle(),
    );
}

Configuration

Add configuration to config.yml.

Log in to Mandrill and go to "Settings" -> "SMTP & API Info". Create an API Key and use it in your Symfony2 Configuration.

# config.yml

hamaryuginh_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

Now you're all set, send your first transactional mails:

Use

Send an email from a Controller:

/* Prepare the Message */
$mandrillMessage = new Message();
$mandrillMessage
    ->setSubject('Message subject')
    ->setHtml('<html><body>HTML content goes here</body></html>')
    ->setText('Text content goes here')
    ->setFromEmail('from.me@foo.bar')
    ->setFromName('From Me')
    ->addTo('john.doe@foo.bar')
    ...
;

/* Get the Mandrill Manager */
$mandrillManager = $this->get('hamaryuginh.mandrill_manager');

/* Get Mandrill Message Service */
$mandrillMessage = $mandrillManager->get('message');

/* Send the Message : this method return a MessageResponse */
$messageResponse = $mandrillMessage->send($mandrillMessage);

The send method has the following signature:

/**
 * Send a new transactional message through Mandrill
 * @param Message $message
 * @param boolean $async
 * @param string $ipPool
 * @param string $sendAt
 * @return MessageResponse|false - Return false if the parameter disable_delivery (in the config) is set to true
 */
public function send(Message $message, $async = false, $ipPool = null, $sendAt = null)