Created
July 30, 2010 11:16
-
-
Save bogomil/500334 to your computer and use it in GitHub Desktop.
How to send an SMS using Twilio SMS REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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