dev-master
9999999-devSendinblue integration and Mailer for the Yii framework
MIT
The Requires
The Development Requires
email yii2 mailer sendinblue
Sendinblue integration and Mailer for the Yii framework
Provide the following classes:, (*1)
The choice between the two message types is made automatically by the compose()
method., (*2)
Install this package in Yii project root with Composer., (*3)
composer require silverback/yii2-sendinblue
, (*4)
Setup the Sendinblue mailer in app config:, (*5)
'components' => [ //... 'mailer' => [ 'class' => 'yii\sendinblue\transactional\Mailer', 'apikey' => 'your-sedinblue-api-key', ], //... ]
$viewAttributes = array( 'attribute1' => 'value1', ); $message = \Yii::$app->mailer->compose('view-name', $viewAttributes); $message->setFrom( 'noreply@example.com' ); $message->setSubject( 'Subject' ); $message->setTo( 'user@example.com' ); if ( $message->send() ) { echo "Sent successfully"; }
$message = \Yii::$app->mailer->compose(); $message->setFrom( 'noreply@example.com' ); $message->setSubject( 'Subject' ); $message->setTo( 'user@example.com' ); $message->setTextBody( 'test content' ); if ( $message->send() ) { echo "Sent successfully"; }
$template_id = 1; $templateAttributes = array( 'attr1' => 'value1', 'attr2' => array( 'subattr1' => 'value2', 'subattr2' => array( 'subsubattr1' => 'value2', ) ), ); // The class uses Sendiblue templates when the view name is an integer instead of string. $message = \Yii::$app->mailer->compose( $template_id, $templateAttributes ); $message->setTo( 'user@example.com' ); if ( $message->send() ) { echo "Sent successfully"; }
The following attributes will be available as replacements in the template:, (*6)
%ATTR1% %ATTR2__SUBATTR1% %ATTR2__SUBATTR2__SUBSUBATTR1%
All attributes will be converted and must be used in uppercase., (*7)
This class uses PHPUnit as test suite, to test the classes and functions follow this steps., (*8)
Copy the file phpunit.xml.dist
in phpunit.xml
in the library folder and define Api-Key and addresses inside it:, (*9)
<php> <const name="SENDINBLUE_API_KEY" value="{your-key}"/> <const name="SENDINBLUE_TEMPLATE" value="1"/> <const name="SENDINBLUE_FROM" value="from@example.com"/> ... </php>
Launch a composer update
to install all the dependencies and test suite., (*10)
Run the test with the following commands, (*11)
./vendor/bin/phpunit tests/ # all tests ./vendor/bin/phpunit tests/TemplateMessageTest # single test
Sendinblue integration and Mailer for the Yii framework
MIT
email yii2 mailer sendinblue