Sending SMS messages via Twilio Rest API

July 30, 2010
By Bogomil Shopov
Post Image

I am looking at Twilio API right now for a project and I am surprised how easy is to handle voice and SMS messages. Here is an example, written by me:

ApiVersion = "2008-08-01";
	$this->AccountSid = "Axxxxxxxxxxxxxxxxxxxx"; //get your own after trial registration on
	$this->AuthToken = "axxxxxxxxxxxxxxxxxxxxx";
	$this->smsServer = new TwilioRestClient($this->AccountSid, $this->AuthToken);

function sendSMS($to, $from, $whattosend)

	$response = $this->smsServer->request("/$this->ApiVersion/Accounts/$this->AccountSid/SMS/Messages", 
			"POST", array(
			"To" => $to,
			"From" => $from,
			"Body" => $whattosend
			echo "Error: {$response->ErrorMessage}";
			echo "Done";


function __destruct()



$s= new Twillio_SMS;
$s->sendSMS('4155992671','4155992671','this is a test');


If you are interested in this topic, or if you have some ideas, please join me at my test repo @ Github

Bogomil Shopov

I care about privacy, ethical design, and freedom in many aspects. I spend 20+ years working as a web developer and architect, analyst, manager, and product owner/manager in different environments, several countries, and multiple software industries like Healthcare and Hospitality. I wore many hats, and I use the knowledge gathered to optimize the flow of value across complex systems.


  • parul yadav

    August 14, 2010 at 2:37 pm

    We have specialised packages for various industries including Automobile Industry, Share Traders, Schools / Colleges, Events & Exhibitors and can design customised applications. Our APIs help you in automating the process of sending personal customized SMS through your web applications in PHP, ASP, or VB. Get in touch with our Live Customer Support and we will help you out with a solution.

  • Mobile Marketing

    January 17, 2012 at 7:04 pm

    Does this code like this let a website visitor join an sms subscription list? We built an SMS application using twilio’s API and I would like for visitors to join one of my lists from a website by entering their phone # and sending it to my application somehow.


Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.