Forwarding SMS messages to another phone number

When SMS messages are delivered to your Twilio phone number, Twilio will respond based on the application you have configured to that number. These messages are saved in your Twilio SMS logs.

If you'd like to forward SMS to your phone without needing to host your own code, you can use TwiML Bins to do this. 

Simply create a new Bin in your Twilio account and save the following code to it:

<Response>
<Message to="+12065551212">{{From}}: {{Body}}</Message>
</Response>

Then you can head to your Active Numbers page, set your Messaging URL to configure with "Webhooks/Twiml," and select your TwiML Bin from the available drop-down. You're all set!

 

Alternately, you might want to build SMS forwarding functionality from scratch and host it on your own server. If that's the case, you can use the following PHP code:

<?php header('Content-Type: text/html'); ?>
<Response>
    <Message to="<?=$_REQUEST['PhoneNumber']?>"> <?=htmlspecialchars(substr($_REQUEST['From'] . ": " . $_REQUEST['Body'], 0, 1600))?> </Message>
</Response>

If you save this code to your server as http://example.com/sms_forward.php, then you would configure your Twilio phone number with an SMS request URL like this: http://example.com/sms_forward.php?PhoneNumber=%2B12025551212

Make sure you place the phone number you want to forward SMS messages to in the PhoneNumber parameter of the URL-encoding.

Have more questions? Submit a request
Powered by Zendesk