25/07
2018
, (*1)
LUYA and Yii Framework integration for Mailjet service., (*3)
Contains:, (*4)
Install the extension through composer:, (*5)
composer require luyadev/luya-mailjet
Add to config:, (*6)
'components' => [ //... 'mailjet' => [ 'class' => 'luya\mailjet\Client', 'apiKey' => '...', 'apiSecret' => '...', ], 'mailer' => [ 'class' => 'luya\mailjet\Mailer', ], ]
Sending transactional E-Mail:, (*7)
Yii::$app->mailer->compose() ->setFrom('from@domain.com') ->setTo('to@domain.com') ->setSubject('Message subject') ->setTextBody('Plain text content') ->setHtmlBody('<b>HTML content</b>') ->send();
Send a transactional E-Mail based on the Template id stored in Mailjet:, (*8)
Yii::$app->mailer->compose() ->setTemplate(484590) ->setVariables(['lastname' => 'Lastname Value']) ->setTo(['to@domain.com']) ->send();
With version 1.3 of LUYA Mailjet library there is an admin module you can configured in order to parser MJML into HTML, therefore add the module to your configuration and provide mjml.io API keys:, (*9)
'modules' => [ //... 'mailjetadmin' => [ 'class' => 'luya\mailjet\admin\Module', 'mjmlApiApplicationId' => 'ApplicationIdFromMjml.io', 'mjmlApiSecretKey' => 'ApplicationSecretFromMjml.io', ] ]
Afterwards you can retrieve and render the HTML of MJML template with:, (*10)
luya\mailjet\models\Template::renderHtml('slug', ['foo' => 'bar']);