2017 © Pedro Peláez
 

yii2-extension yii2-sendinblue

Sendinblue integration and Mailer for the Yii framework

image

silverback/yii2-sendinblue

Sendinblue integration and Mailer for the Yii framework

  • Friday, July 20, 2018
  • by brandomeniconi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yii2 Framework Sendinblue Mailer and Contacts integration

Provide the following classes:, (*1)

The choice between the two message types is made automatically by the compose() method., (*2)

Installation

Install this package in Yii project root with Composer., (*3)

composer require silverback/yii2-sendinblue, (*4)

Setup

Setup the Sendinblue mailer in app config:, (*5)


'components' => [ //... 'mailer' => [ 'class' => 'yii\sendinblue\transactional\Mailer', 'apikey' => 'your-sedinblue-api-key', ], //... ]

Usage

Send email using a view (standard Yii behavior)


$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"; }

Send email with custom text


$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"; }

Send email with Sendinblue template


$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)

Testing

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

The Versions

20/07 2018

dev-master

9999999-dev

Sendinblue integration and Mailer for the Yii framework

  Sources   Download

MIT

The Requires

 

The Development Requires

email yii2 mailer sendinblue