Skip to content

Instantly share code, notes, and snippets.

@bogomil
Created July 30, 2010 11:16
Show Gist options
  • Save bogomil/500334 to your computer and use it in GitHub Desktop.
Save bogomil/500334 to your computer and use it in GitHub Desktop.
How to send an SMS using Twilio SMS REST API
<?php
//get this from twillio website
require "twilio.php";
class Twillio_SMS
{
var $ApiVersion;
var $AccountSid;
var $AuthToken;
var $smsServer;
function __construct()
{
$this->ApiVersion = "2008-08-01";
$this->AccountSid = "Axxxxxxxxxxxxxxxxxxxxxxxxxx";
$this->AuthToken = "axxxxxxxxxxxxxxxxxxxxxxxxxxx";
$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
));
if($response->IsError)
echo "Error: {$response->ErrorMessage}";
else
echo "Sent message to $name";
}
function __destruct()
{
unset($this->ApiVersion);
unset($this->AccountSid);
unset($this->AuthToken);
unset($this->CallerID);
}
}
$s= new Twillio_SMS;
$s->sendSMS('4155992671','4155992671','this is a test');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment