mipotech / yii2-pulseem

通过 Yii2 使用 Pulseem API 的包装函数集合

安装: 49

依赖者: 0

建议者: 0

安全性: 0

星标: 2

关注者: 2

分支: 0

开放问题: 0

类型:yii2-extension

1.0 2017-07-11 13:03 UTC

This package is auto-updated.

Last update: 2024-09-29 05:02:08 UTC


README

本软件包提供了一种简单的方式来使用 Pulseem 进行邮件和短信发送。

安装

安装此扩展的首选方式是通过 composer

首先将此条目添加到 composer.json 文件中的 repositories 部分

"repositories": [{
    ...
},{
    "type": "git",
    "url": "https://github.com/mipotech/yii2-pulseem.git"
},{
    ...
}],

然后添加以下行

"mipotech/yii2-pulseem": "dev-master",

composer.json 文件的 require 部分,并执行 composer update。

配置

将以下部分添加到 params 文件 (@app/config/params.php)

return [
    ...
    
    'pulseem' => [
        // Basic config
        'password' => '...',
        'username' => '...',
        //'endpoint' => '...', // Optionally configure a custom endpoint instead of the default
        
        // For email operations (optional)
        'fromEmail' => '...',
        'fromName' => '...'
        
        // For SMS operations (optional)
        'senderPhone' => '...',
    ],
    ...
];

这就完成了。该软件包已设置完毕,准备使用。

用法

创建 SDK 实例

use mipotech\pulseem\PulseemSdk;

$pulseem = new PulseemSdk();

发送单封邮件

标准

$params = [
    'htmlBody' => '<p>Body here</p>',
    'subject' => 'Testing',
    'toEmail' => 'test@test.com',
];
$res = $pulseem->sendSingleEmail($params);

使用 Yii2 视图

$params = [
    'subject' => 'Testing',
    'toEmail' => 'test@test.com',
];
$bodyTemplate = '@app/views/emails/customTeplate';
$bodyParams = [
    'model' => $model,
    'index' => $i,
]
$res = $pulseem->sendSingleEmail($params, $bodyTemplate, $bodyParams);

发送具有每个消息独特内容的群发邮件

此类群发邮件要求在 $params 中传递 htmlBodies 数组。

$params = [
    'htmlBodies' => [
        '<p>Body here 1</p>',
        '<p>Body here 2</p>',
    ],
    'subjects' => [
        'Testing 1',
        'Testing 2',
    ],
    'toEmails' => [
        'test1@test.com',
        'test2@test.com',
    ],
    'toNames' => [
        'Test User 1',
        'Test User 2',
    ],
];
$res = $pulseem->sendGroupEmail($params);

发送具有相同内容的群发邮件

此类群发邮件支持两种选项:明确指定 htmlBody 或使用 Yii2 视图。

$params = [
    'htmlBody' => '<p>Body here</p>',
    'subject' => 'Testing',
    'toEmails' => [
        'test1@test.com',
        'test2@test.com',
    ],
    'toNames' => ['Test 1', 'Test 2'],
];
$res = $pulseem->sendGroupSameEmail($params);

发送单条短信

$res = $pulseem->sendSingleSms('+972541112222', 'Testing', [
    'delayDeliveryMinutes' => 1,    // optional
    'externalRef' => '111222',      // optional
]);