Skip to content

Forward SMS Messages from Twilio to Mobile Phone PHP Script

by Jon on June 16th, 2013

I wrote this PHP script to forward sms message from phone numbers to a mobile phone. I have a few old mobile phone numbers I ported to twilio so I could keep the number active and in my possession. The below script receives an incoming sms and then forwards it to a mobile phone number.

// Include the Twilio-PHP library from,
// and move it into the folder containing this file.
require "Services/Twilio.php";

switch ($_REQUEST['To']) // # sms sent to
case "+1407NXXXXXX": // twilio # to match
$phone_number = "+1941NXXXXXX"; // forwarding #

case "+1941NXXXXXX": // this is a twilio phone number
$phone_number = "+1941NXXXXXX"; // forwarding #

// Your Account SID from
// Your Auth Token from

// Instantiate a new Twilio REST Client
$client = new Services_Twilio($sid, $token);

// Set the body of your SMS messages
$body = $_REQUEST['From'].": ".$_REQUEST['Body'];

// Create the message
$sms = $client->account->sms_messages->create($_REQUEST['To'],$phone_number,$body);

print $sms;

Once the script is hosted from a web server, I use Rackspace cloud, go to the phone number settings in Twilio to assign the webpage url as seen in the below screenshot.


From → Internet, Linux, VOIP

  1. Daimel Luis permalink

    Where says (To) also goes my number phone. I sorry for my english

  2. mercy permalink

    hello, it shows me this error

    Warning: curl_exec() has been disabled for security reasons in /home/u670233546/public_html/Services/Twilio/TinyHttp.php on line 95 Fatal error: Uncaught exception ‘Services_Twilio_TinyHttpException’ in /home/u670233546/public_html/Services/Twilio/TinyHttp.php:119 Stack trace: #0 /home/u670233546/public_html/Services/Twilio.php(179): Services_Twilio_TinyHttp->__call(‘post’, Array) #1 /home/u670233546/public_html/Services/Twilio.php(179): Services_Twilio_TinyHttp->post(‘/2010-04-01/Acc…’, Array, ‘From=&To=&Body=…’) #2 /home/u670233546/public_html/Services/Twilio/ListResource.php(92): Base_Services_Twilio->createData(‘/2010-04-01/Acc…’, Array) #3 /home/u670233546/public_html/Services/Twilio/Rest/SmsMessages.php(16): Services_Twilio_ListResource->_create(Array) #4 /home/u670233546/public_html/prueba.php(30): Services_Twilio_Rest_SmsMessages->create(NULL, NULL, ‘: ‘) #5 {main} thrown in /home/u670233546/public_html/Services/Twilio/TinyHttp.php on line 119

    please help me
    in this site:

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

%d bloggers like this: