Google Ad

CakePHP SMS Component

Date: Thu, Jul 30th 2009, 02:16 Author: nick Views: 13689 Comments share

CakePHP WebTechNick Plugin

Get it:
  • Download Now
  • git clone git:// WebTechNick
NOTE: The SMS Component is now apart of the WebTechNick Plugin for easy portability.

I've developed a simple free SMS gateway component based on the information provided in .

This component aims to be as easy as the Email component but for text messages.

This component is in beta and only tested with Sprint, AT&T, and VerizonWireless as those are the only carriers I have access to.
1) Move the sms.php into your /app/controllers/components/ directory
2) Add Sms to the component list in the controller you want to use it in
  1. var $components = array('Sms');

You use the Sms component much like you would the Email component.

  1. $this->Sms->number = '5551234567'; //10 digit cellphone number
  2. $this->Sms->carrier = 'Sprint'; //carrier string
  3. $this->Sms->from = '5553331111'; //10 digit cellphone number OR email address
  4. $this->Sms->text = 'This is a text message'; //Body of text message.
  5. $this->Sms->send(); //Actually send the text message.

Or you can pass in these properties as an options array.
  1. $this->Sms->send(array(
  2.   'number' => '5551234567', //10 digit cellphone number
  3.   'carrier' => 'Sprint', //carrier string
  4.   'text' => 'This is a text', //Body of the text message
  5.   'from' => '5553331111' //10 digit cellphone number OR email address
  6. ));

Testing SMS component:
The SMS component has a built in testSend feature that will test if the SMS is ready to be sent or not.
  1. if($this->Sms->testSend()){
  2.   //Hurray, we can send it!
  3.   $this->Sms->send();
  4. } else {
  5.   //Oh no, can't send it, check the errors log to see why
  6.   debug($this->Sms->errors);
  7. }

Built In Carrier String List:

  'ATT'           //AT&T
  'Boost'        //Boost Mobile
  'Cellular One'  //Cellular One
  'Cingular'      //Cingular
  'Cricket'      //Cricket
  'Nextel'        //Nextel
  'Sprint'        //Sprint
  'Qwest'        //Qwest
  'TMobile'       //T-Mobile
  'Verizon'      //Verizon Wireless
  'Virgin'        //Virgin Mobile

I've picked out the most common carriers in my area and for my own purposes, but its very easy to add more by adding it to the carrierDomain associative array.
  1. function beforeFilter(){
  2.   $this->Sms->carrierDomain['NewCarrier'] = '';
  3.   parent::beforeFilter();
  4. }

Then you could reference you're new carrier like so:
  1. $this->Sms->carrier = 'NewCarrier';
  2. $this->Sms->number = '5555551234';
  3. $this->Sms->text = 'This is a text message to NewCarrier';
  4. $this->Sms->send();

I hope you find this component useful.