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.
If you use Composer, you can update your composer.json like this :
{
"require": {
"softbread/yii2-sendcloud": "@dev"
}
}
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('[email protected]')
->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('[email protected]')
->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