2017 © Pedro Peláez
 

cakephp-plugin mandrill

This enables using CakeEmail from CakePHP 2.x with Mandrill

image

jmillerdesign/mandrill

This enables using CakeEmail from CakePHP 2.x with Mandrill

  • Wednesday, June 10, 2015
  • by jmillerdesign
  • Repository
  • 3 Watchers
  • 2 Stars
  • 340 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 18 Forks
  • 0 Open issues
  • 4 Versions
  • 39 % Grown

The README.md

Mandrill CakePHP Plugin

This enables using CakeEmail from CakePHP 2.0 with Mandrill., (*1)

Installation

  1. Copy this directory to /app/Plugin/Mandrill (or if you want you can use as a submodule):, (*2)

    git clone https://github.com/jmillerdesign/MandrillTransport-CakePHP.git app/Plugin/Mandrill;
  2. Add an email configuration for the Mandrill Transport protocol. Add this to /app/Config/email.php. You may find it named email.php.default., (*3)

    public $mandrill = array(
        'transport' => 'Mandrill.Mandrill',
        'uri' => 'https://mandrillapp.com/api/1.0/',
        'key' => 'your-key-here'
    );

    Be sure to update the API Key to your own key., (*4)

  3. Load the plugin in /app/Config/bootstrap.php., (*5)

    CakePlugin::load('Mandrill');

Config

Mandrill has many options that can be passed with messages, which are described in the Mandrill API Documentation. You can pass these to this plugin in the email configuration (ex. 1) or with $email->config() (ex. 2)., (*6)

Example 1 (global config)
    public $mandrill = array(
        'transport' => 'Mandrill.Mandrill',
        'uri' => 'https://mandrillapp.com/api/1.0/',
        'key' => 'your-key-here',
        'track_opens' => true,
        'track_clicks' => true
    );
Example 2 (instance config)
    $email->config(array(
        'tags' => array('password_reset'),
        'template_name' => 'password_reset',
        'auto_html' => false
    ));

Outbound Email Usage

Usage is based on the CakeEmail class and specification., (*7)

To use, import the CakeEmail class:, (*8)

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

and use it like so when you want to send an email., (*9)

$email = new CakeEmail();
$email->config('mandrill');
$email->from('noreply@yourapp.com');
$email->to('email@domain.com');
$email->subject('Subject for Email');
$result = $email->send();

The $result object will contain information about the success or failure of the message sending. $result will contain the Mandrill key, which contains the response from Mandrill., (*10)

Use template settings for from and subject

In the above example, if you don't set $email->subject(), then it will use Mandrill's template setting instead. If you set the from email address and/or name to mandrill@example.com, then it will use Mandrill's template setting instead. Note: Setting a from address is required by Cake., (*11)

Inbound Email Usage

  1. Configure mandrillapp.com/inbound and point the Webhook to http://example.com/mandrill/emails/inbound (replace example.com with your live domain URL)
  2. Create an event handler if you want to do something whenever you receive an email. In your controller:, (*12)

    <?php
    /**
     * Handle inbound email
     *
     * @param CakeEvent $event Event object
     * @return void
     */
        public function handleInboundEmail($event) {
            // Do something with the event
            CakeLog::write('debug', print_r($event->data, true));
        }
  3. In Config/bootstrap.php, add the following, to send the event to your controller. Replace "YourController" with the name of the controller where you placed the handleInboundEmail method., (*13)

    <?php
    /**
     * Handle inbound Mandrill email
     * Pass it off to YourController->handleInboundEmail()
     */
    App::uses('CakeEventManager', 'Event');
    CakeEventManager::instance()->attach('handleInboundEmail', 'Mandrill.inbound');
    function handleInboundEmail($event) {
        App::uses('YourController', 'Controller');
        $controller = new YourController();
        $controller->handleInboundEmail($event);
    }
  4. Attachments are automatically saved and can be publicly accessed at: http://example.com/mandrill/attachments/{MessageID}/{AttachmentName}, (*14)


© Soroush Khanlou 2013
Modified heavily by: J. Miller, (*15)

The Versions

10/06 2015

dev-master

9999999-dev https://github.com/jmillerdesign/MandrillTransport-CakePHP/

This enables using CakeEmail from CakePHP 2.x with Mandrill

  Sources   Download

MIT

The Requires

 

by J. Miller
by Soroush Khanlou

cakephp mandrill transport

20/04 2015

2.2.2

2.2.2.0 https://github.com/jmillerdesign/MandrillTransport-CakePHP/

This enables using CakeEmail from CakePHP 2.x with Mandrill

  Sources   Download

MIT

The Requires

 

by J. Miller
by Soroush Khanlou

cakephp mandrill transport

04/02 2015

2.2.1

2.2.1.0 https://github.com/jmillerdesign/MandrillTransport-CakePHP/

This enables using CakeEmail from CakePHP 2.x with Mandrill

  Sources   Download

MIT

The Requires

 

by J. Miller
by Soroush Khanlou

cakephp mandrill transport

23/11 2014

2.2.0

2.2.0.0 https://github.com/jmillerdesign/MandrillTransport-CakePHP/

This enables using CakeEmail from CakePHP 2.x with Mandrill

  Sources   Download

MIT

The Requires

 

by J. Miller
by Soroush Khanlou

cakephp mandrill transport