软包/yii2-sendcloud

提供用于SendCloud电子邮件服务的Yii2组件

v0.2.0 2018-01-21 10:45 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:07:34 UTC


README

中文文档

此扩展允许开发人员使用SendCloud作为电子邮件传输。此外,您还可以使用此扩展通过SendCloud向中国手机发送短信。此作品受yii2-sendgrid的启发。

安装

如果您使用Composer,可以像这样更新您的composer.json

{
    "require": {
        "softbread/yii2-sendcloud": "@dev"
    }
}

如何使用它

将扩展添加到您的配置中

return [
    //....
    'components' => [
        'mailer' => [
            'class' => 'SendCloud\Mail\Mailer',
            'api_user' => '<your sendcloud api-user>',
            'api_key'  => '<your sendcloud api-key>'
        ],
        'sendSms' => [
            'class'  => 'SendCloud\Sms\SendSms',
            'apiUser => '<your SMS api-user>',
            'apiKey  => '<your SMS api-key>'
        ],
    ],
];

您可以通过SendCloud作为邮件组件发送电子邮件

Yii::$app->mailer->compose('contact/html')
     ->setFrom('from@domain.com')
     ->setTo($form->email)
     ->setSubject($form->subject)
     ->send();

有关更多说明,请参阅Yii definitive guide中的相关部分

您还可以使用SendCloud模板电子邮件

Yii::$app->mailer->compose('contact/html')
     ->setFrom('from@domain.com')
     ->setTo([email1, email2])
     ->setSubject($form->subject)
     ->setTemplateName('revoke-name')
     ->setTemplateVars([
            '%name%' => ['X1', 'X2'],
            '%money%'=> [12.5, 1.9]
        ])
     ->send();

发送短信

Yii::$app->sendSms->setTo(['13700000000', '13011111111'])
    ->setTemplate('1001')
    ->setVars(['code' => '000111'])
    ->send();

有关更多说明,请参阅SendCloud SMS API文档