softbread/yii2-sendcloud

Provides Yii2 component for SendCloud email service

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

This package is not auto-updated.

Last update: 2024-04-22 04:24:58 UTC


README

中文文档

This extension allows developpers to use SendCloud as an email transport. Also, you may use this extension to send SMS messages to Chinese cell phones via SendCloud. This work is inspired by yii2-sendgrid.

Installation

If you use Composer, you can update your composer.json like this :

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

How to use it

Add extension to your configuration

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>'
        ],
    ],
];

You can send email via SendCloud as mailer component

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

For further instructions refer to the related section in the Yii Definitive Guide

Also you can use SendCloud template Emails

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();

To send SMS message:

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

For further instruction refer to the SendCloud SMS API doc