softbread / yii2-sendcloud
Provides Yii2 component for SendCloud email service
Installs: 30
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:libaray
Requires
- php: >=5.5.0
- yiisoft/yii2: ~2.0
- yiisoft/yii2-httpclient: *
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2025-01-13 07:32:59 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