yii-sms Extension to send SMS from Yii using different SMS providers.

  1. Requirements
  2. Installation and configuration
  3. How to use
  4. How to log the SMS that you send
  5. How to add more providers
  6. Resources

This extension allows you to send SMS from Yii using different SMS providers and also save a log of the SMS you send.


This extension will require you to download and install third-party sms providers files before using it.

Installation and configuration

1) Copy to 'extensions' folder

2) Download additional third-party provider files and place them in 'vendor' folder

Twilio: https://github.com/twilio/twilio-php

Note: in TwilioSMSProvider.php file you can see where it looks for the library and adjust it in case you've placed it somewhere else.


3) Configure in main.php

In the "components" section of the configuration file add:

  'class' => 'ext.yii-sms.YiiSMS',
  'defaultProvider' => 'Twilio', // the default provider to use
  // place here a class and a method to call after sending sms if you want to log the sms sent
  // 'afterSend'=>array('ClassName', 'methodName'), 
  'providers' => array(
      'from' => '123456', // Twilio from number
      'account_sid'=>'', // Twilio account_sid
      'auth_token'=>'', // Twilio auth_token

How to use

/* @var $sms YiiSMS */

$to='+34600000000'; // phone number
$text='This is a test SMS'; // text to send

// extra params that can be retrieved if you want to log the SMS that was sent

$sms->send($to, $text, $extra);

How to log the SMS that you send

1) Uncomment 'afterSend' param in the configuration and specify a valid class and method to call:

'afterSend'=>array('ModelSMS', 'logSentMessage'),

2) Define the method that will do the logging inside a class/model:

class ModelSMS extends CActiveRecord

  // ...

  public function logSentMessage($to, $text, $sent, $lastErrorMessage, $extra=array()) {

    $model=new ModelSMS;
    $model->date=date("Y-m-d H:i:s");
    $model->extra_param_name=isset($extra['extra_param_name']) ? $extra['extra_param_name'] : null;
    $model->error_message=!empty($lastErrorMessage) ? $lastErrorMessage : null;



How to add more providers

If you don't want to use it with Twilio and want to add other provider you can follow this steps:

1) Download the provider third-party files/SDK if available and place it somewhere you can load it from (eg: vendor)

2) Create a new provider class under extensions/yii-sms/providers (you can duplicate TwilioSMSProvider.php)

3) Modify and adjust the code inside the new provider class

4) Change the 'defaultProvider' parameter in the configuration so you use this one instead of Twilio


0 0
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Tags: sms
Developed by: atrandafir
Created on: Feb 28, 2015
Last updated: 5 years ago


show all

Related Extensions