Skip to content

a2design-inc/Mandrill-CakePHP-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mandrill CakePHP plugin

Usage

This plugin uses CakeEmail class, and works almost the same.

Basic example:

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('mandrill');

$email->to('[email protected]');
$email->subject('Test email via Mandrill');
$email->send('Message');

More advanced example:

App::uses('CakeEmail', 'Network/Email');

$email = new CakeEmail(array(
    'transport' => 'Mandrill.Mandrill',
    'from' => '[email protected]',
    'fromName' => 'FromName',
    'timeout' => 30,
    'api_key' => 'YOUR_API_KEY',
    'emailFormat' => 'both',
));

$viewVars = array(
    'var1' => 'some1',
    'var2' => 'some2'
);

$to = array(
    '[email protected]',
    '[email protected]',
);

$email->addHeaders(array(
    'tags' => array('test',),
    'subAccount' => 'YOUR_SUBACCOUNT',
    'preserve_recipients' => false,
    'global_merge_vars' => array(
        array(
            'name' => 'date',
            'content' => date('Y-m-d'),
        ),
    ),
    'merge_vars' => array(
        array(
            'rcpt' => '[email protected]',
            'vars' => array(
                array(
                    'name' => 'email',
                    'content' => '[email protected]'
                ),
                array(
                    'name' => 'name',
                    'content' => 'to1Name'
                ),
            )
        ),
        array(
            'rcpt' => '[email protected]',
            'vars' => array(
                array(
                    'name' => 'email',
                    'content' => '[email protected]'
                ),
                array(
                    'name' => 'name',
                    'content' => 'to2Name'
                ),
            )
        ),
    ),
));

$email->addAttachments(array(
    'example.pdf' => array(
        'file' => APP . '/webroot/files/readme.pdf',
        'mimetype' => 'application/pdf',
    ),
    'logo.png' => array(
        'file' => APP . '/webroot/img/logo.png',
        'mimetype' => 'image/png',
//      'contentId' => 'headerLogo', // Uncomment this line if you want use inline image
));

$email->template('test', 'default');
$email->viewVars($viewVars);
$email->to($to);
$email->subject('Mandrill CakePHP Plugin Test');

$email->send();

Part of email template:

<p>Global vars example. Here the current date: *|date|*</p>
<p>Email sent for *|name|* (*|email|*)</p>

About sub accounts you can read here.

The syntax of all parameters is the same as the default CakeEmail class.

Installation

You can clone the plugin into your project:

cd path/to/app/Plugin
git clone [email protected]:a2design-company/Mandrill-CakePHP-plugin.git Mandrill

Also you can use composer for install this plugin. Just add new requirement to your composer.json

"require": {
    ...,
    "a2design-company/mandrill-cakephp-plugin": "*"
},

Bootstrap the plugin in app/Config/bootstrap.php:

CakePlugin::load('Mandrill');

Configuration

Create the file app/Config/email.php with the class EmailConfig.

<?php
class EmailConfig {
	public $mandrill = array(
        'transport' => 'Mandrill.Mandrill',
        'from' => '[email protected]',
        'fromName' => 'FromName',
        'timeout' => 30,
        'api_key' => 'YOUR_API_KEY',
        'emailFormat' => 'both',
    );
}

Requirements

CakePHP 2.0+

License

Licensed under The MIT License

Developed by A2 Design Inc.