dev-master
9999999-devMandrill Api Integration for Yii2
GPL-3.0
The Requires
by Sumit Ahuja
email extension yii2 mailer mandrill
Mandrill Api Integration for Yii2
Mandrill Api Integration for Yii2
, (*1)
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist nickcv/yii2-mandrill "*"
or add, (*4)
"nickcv/yii2-mandrill": "*"
to the require section of your composer.json
file., (*5)
To use Mandrill you will need to have a Mandrill Account., (*6)
Every single account can send up to 12k emails per month for free., (*7)
The cost for sending emails over that threshold is really low., (*8)
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., (*9)
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., (*10)
Once the extension is installed, change your application config file web.php
:, (*11)
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., (*12)
'id' => 'basic', 'name' => 'Application Name',
return [ 'adminEmail' => 'admin@example.com', ];
You will then need to add the component, (*13)
'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., (*14)
\Yii::$app->mailer ->compose('mailViewName', ['model' => $model]) ->setTo('email@email.com') ->send();
You can use Mandrill's own template system if you want to, just set up as true the useMandrillTemplates
attribute in the component configuration, (*15)
'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., (*16)
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., (*17)
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., (*18)
To override this behavior you can set to false the useTemplateDefaults
attribute in the component configuration, (*19)
'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)., (*20)
For more information about handlebars usage check these links:, (*21)
You can change preferred language by editing templateLanguage
attribute in the component configuration, (*22)
'mailer' => [ 'class' => 'nickcv\mandrill\Mailer', 'apikey' => 'YourApiKey', 'useMandrillTemplates' => true, 'templateLanguage' => nickcv\mandrill\Mailer::LANGUAGE_HANDLEBARS, ],
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:, (*23)
\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., (*24)
\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., (*25)
Since version 1.6.0 you can get the Mandrill object used by the component calling the Mailer::getMandrill
method., (*26)
For more informations check the component documentation., (*27)
All the Classes within the package have been unit tested.
The tests are included within the package., (*28)
If you wish to run the tests install codeception following the Yii2 documentation., (*29)
The tests use the developer Mandrill Test API key which is only whitelisted for the developer IP., (*30)
The component automatically logs every single message sent through mandrill, inside the "mandrill" category., (*31)
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()
., (*32)
If you are using mandrill templates and the template is not found the error will be logged using Yii::info()
., (*33)
Mandrill Api Integration for Yii2
GPL-3.0
email extension yii2 mailer mandrill