承接 silverback/yii2-sendinblue 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

silverback/yii2-sendinblue

最新稳定版本:1.0.1

Composer 安装命令:

composer require silverback/yii2-sendinblue

包简介

Sendinblue integration and Mailer for the Yii framework

README 文档

README

Provide the following classes:

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

Installation

Install this package in Yii project root with Composer.

composer require silverback/yii2-sendinblue

Setup

Setup the Sendinblue mailer in app config:

    '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:

%ATTR1%
%ATTR2__SUBATTR1%
%ATTR2__SUBATTR2__SUBSUBATTR1%

All attributes will be converted and must be used in uppercase.

Testing

This class uses PHPUnit as test suite, to test the classes and functions follow this steps.

Copy the file phpunit.xml.dist in phpunit.xml in the library folder and define Api-Key and addresses inside it:

	<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.

Run the test with the following commands

./vendor/bin/phpunit  tests/  # all tests
./vendor/bin/phpunit  tests/TemplateMessageTest # single test

统计信息

  • 总下载量: 1.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固