2017 © Pedro Peláez
 

yii2-extension yii2-mandrill

Mandrill Api Integration for Yii2

image

nickcv/yii2-mandrill

Mandrill Api Integration for Yii2

  • Wednesday, June 27, 2018
  • by nickcv
  • Repository
  • 6 Watchers
  • 27 Stars
  • 59,394 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 24 Forks
  • 3 Open issues
  • 12 Versions
  • 9 % Grown

The README.md

Mandrill API Extension

Mandrill Api Integration for Yii2 Latest Stable Version build Total Downloads License, (*1)

Change Log

Since version 1.6.1 the methods nickcv\mandrill\Message::setHtmlBody and nickcv\mandrill\Message::setSubject do not purify/encode the data automatically., (*2)

This has been done to offer a greater degree of flexibility to developers, see issues #16 and #19., (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist nickcv/yii2-mandrill "*"

or add, (*6)

"nickcv/yii2-mandrill": "*"

to the require section of your composer.json file., (*7)

Set Up

Recently Mandrill became a MailChilmp service: to use Mandrill you will need to have a MailChimp Account., (*8)

For details on the pricing please check their website., (*9)

Once you have an account you will need to create an API Key. You can create as many API keys as you want, and it's best practice to create one for each website. You can also create test API keys. Every email submitted using a test API key will not actually be submitted, but you'll be able to check inside the test dashboard if the test went thorugh successfully., (*10)

Mandrill will keep track of every single email you submit. You can filter the data using tags and you'll also be able to check how many times each email was opened and if the links within it have been clicked., (*11)

Usage

Once the extension is installed, change your application config file web.php:, (*12)

First of all you will need to add an application name. By default this extension will send every single email using the application name as the sender name and the adminEmail parameter inside params.php as the sender email., (*13)

[
    'id' => 'basic',
    'name' => 'Application Name',
]
return [
    'adminEmail' => 'admin@example.com',
];

You will then need to add the component, (*14)

    'mailer' => [
        'class' => 'nickcv\mandrill\Mailer',
        'apikey' => 'YourApiKey',
    ],

From now on you can just use the mandrill mailer just as you used to use the default one., (*15)

\Yii::$app->mailer
    ->compose('mailViewName', ['model' => $model])
    ->setTo('email@email.com')
    ->send();

Mandrill Templates

You can use Mandrill's own template system if you want to, just set up as true the useMandrillTemplates attribute in the component configuration, (*16)

    'mailer' => [
        'class' => 'nickcv\mandrill\Mailer',
        'apikey' => 'YourApiKey',
        'useMandrillTemplates' => true,
    ],

If you do turn this feature on the component will look for a template within mandrill named after the view argument of the compose method., (*17)

Since version 1.3.0 the component will stop falling back to rendering the internal views. This change has been made because now the mandrill send-template method will be used, avoiding to make two API calls when templates are enabled., (*18)

Since version 1.4.0 the component won't default to the application name and admin email when using mandrill templates. This has been done to allow the use of Mandrill defaults values for the template., (*19)

To override this behavior you can set to false the useTemplateDefaults attribute in the component configuration, (*20)

    'mailer' => [
        'class' => 'nickcv\mandrill\Mailer',
        'apikey' => 'YourApiKey',
        'useMandrillTemplates' => true,
        'useTemplateDefaults' => false,
    ],

Since version 1.5.0 the component has a configurable property templateLanguage that can contain either 'mailchimp' or 'handlebars' ('mailchimp' is by default)., (*21)

For more information about handlebars usage check these links:, (*22)

You can change preferred language by editing templateLanguage attribute in the component configuration, (*23)

    'mailer' => [
        'class' => 'nickcv\mandrill\Mailer',
        'apikey' => 'YourApiKey',
        'useMandrillTemplates' => true,
        'templateLanguage' => nickcv\mandrill\Mailer::LANGUAGE_HANDLEBARS,
    ],

Additional Methods

Mandrill lets you set up tags. The method \nickcv\mandrill\Message::setTags($tags) accept as an argument both a string or an array of strings:, (*24)

\Yii::$app->mailer
    ->compose('mailViewName', ['model' => $model])
    ->setTags(['registration']);

Since version 1.3.0 it's also possible to enable the async mode. When using async mode mandrill will queue the messages and send em in batches. If you send a message to more than 10 email addresses async mode will be used automatically., (*25)

\Yii::$app->mailer
    ->compose('mailViewName', ['model' => $model])
    ->enableAsync();

Since version 1.4.0 it's also possible to use global merge vars. This variables will be use to replace placeholders by mandrill. This is especially useful when dealing with templates., (*26)

Since version 1.6.0 you can get the Mandrill object used by the component calling the Mailer::getMandrill method., (*27)

For more informations check the component documentation., (*28)

Since version 1.7.0 it's also possible to enable/disable messages clicks/opens tracking and to decide whether or not it is a priority message., (*29)

It is also possible to retrieve the full body of the response returned from Mandrill using the Mailer::getLastTransaction method., (*30)

Sending Multiple Email with Mandril Template using merge_vars, (*31)

You can consider using this method for using mandrill template and change the variable based on your data :, (*32)

\Yii::$app->mailer
    ->compose($stringTemplate)
    ->setTo($arrayTo)
    ->setGlobalMergeVars($arrayGolbalMergeVars)
    ->setMergeVars($arrayMergeVars)
    ->send();

Unit Testing

All the Classes within the package have been unit tested. The tests are included within the package., (*33)

If you wish to run the tests install phpunit following the Yii2 documentation., (*34)

The tests use the developer Mandrill Test API key which is only whitelisted for the developer IP., (*35)

Logs

The component automatically logs every single message sent through mandrill, inside the "mandrill" category., (*36)

Messages sent successfully are logged using \Yii::info(), messages rejected or invalid are logged using \Yii::warning(), and all the exceptions thrown by the Mandrill Class are logged using \Yii::error()., (*37)

If you are using mandrill templates and the template is not found the error will be logged using Yii::info()., (*38)

The Versions

27/06 2018

dev-master

9999999-dev

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Nicola Puddu
by Simon Karlen

email extension yii2 mailer mandrill

27/06 2018

1.8.0

1.8.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Nicola Puddu
by Simon Karlen

email extension yii2 mailer mandrill

10/06 2016

1.7.0

1.7.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Nicola Puddu

email extension yii2 mailer mandrill

22/10 2015

1.6.1

1.6.1.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

21/08 2015

1.6.0

1.6.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

09/06 2015

1.5.0

1.5.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

13/05 2015

1.4.0

1.4.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

21/04 2015

1.3.0

1.3.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

03/03 2015

1.2.0

1.2.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

27/01 2015

1.1.1

1.1.1.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

21/01 2015

1.1

1.1.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill

14/08 2014

1.0

1.0.0.0

Mandrill Api Integration for Yii2

  Sources   Download

GPL-3.0

The Requires

 

by Nicola Puddu

email extension yii2 mailer mandrill