Skip to content

Yii2 component for sending emails and SMS messages via SendCloud

License

Notifications You must be signed in to change notification settings

softbread/yii2-sendcloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SendCloud Yii2 integration

中文文档

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

About

Yii2 component for sending emails and SMS messages via SendCloud

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages