Forwarding SMS messages to another phone number

It's easy to forward your Twilio SMS messages to another destination. Whether you're an experienced developer, or have never written a line of code, we offer a number of versatile products to help you get up and running quickly. Read on for more details and instructions to get your Twilio phone number configured for this use case.

Please note, it is also possible to forward incoming Twilio SMS messages to an email address. For more information, please see our article on Forwarding SMS Messages to your Email Inbox.

SMS Message Forwarding with Twilio Studio (Beta)

Twilio Studio provides a visual interface to drag and drop widgets, with no programming experience required. For more information on Twilio Studio, please see our landing page here: www.twilio.com/studio.

Recommended for: Twilio users who aren't familiar with code, don't have their own web hosting, or just want to get up and running as quickly as possible.

Set up: Setting up Twilio Studio to forward SMS messages only requires a Send Message widget, and a bit of configuration. For a full walkthrough, please see our article for Forwarding Incoming SMS Messages with Twilio Studio.

SMS Message Forwarding with TwiML Bins

TwiML Bins allow for simple XML scripting with little to no programming experience needed. For more information on TwiML Bins, please see our blog post here: TwiML Bins: A Serverless and Codeless Way to Try Twilio

Recommended for: Twilio users who want a bit more customization options, but don't have their own web hosting.

Set up: Setting up a TwiML Bin only requires creating the bin, adding a few lines of code, and then configuring it on your number. Here are the instructions:

  1. Login to your account at www.twilio.com.
  2. Click Runtime.
  3. Click TwiML Bins, and then select Create New TwiML Bin, or the red plus + sign button.
  4. Add a Friendly Name and some TwiML, and then click Create.
    • Friendly Name: This is up to you - we select using something that gives an idea of what the TwiML Bin will do like “Forward SMS”.
    • TwiML: For the code, you will use the <Message> Verb, along with some Mustache Templates to pull information from the HTTP request parameters. Update the “to” phone number nested within the <Message> tags to your target phone number for receiving forwarded SMS messages, and you should end up with something like this:
      <Response>
          <Message to='+13105555555'>{{From}}: {{Body}}</Message>
      </Response>
  5. Configure this TwiML bin on your Twilio number by following the steps here: Configuring phone numbers to receive calls or SMS messages.

SMS Message Forwarding with Twilio Functions (Beta)

Twilio Functions provide a Twilio-hosted webhook event responder, with limited programming experience required. For more information on Twilio Functions, please see our landing page here:www.twilio.com/functions.

Recommended for: Twilio users who don't have their own web hosting, and want a versatile solution that can be as simple or complex as needed.

Setup: Setting up a Twilio Function for forwarding SMS messages only requires a few lines of code. Here are the instructions:

  1. Login to your account at www.twilio.com.
  2. Click Runtime.
  3. Click Functions, and then select Create a Function, or the red plus + sign button.
  4. Select the Blank template, and then click Create.
  5. Add a Path and update the CODE field, and then click Save.
    • Path: This is up to you - we select using something that gives an idea of what the Function will do like “forwardSMS”.
    • CODE: In this field, copy and paste the code below. Be sure to update line 4; The ‘To’ number should be changed to your target phone number for receiving forwarded SMS messages.
      exports.handler = function(context, event, callback) {
        let twiml = new Twilio.twiml.MessagingResponse();
        twiml.message(`${event.From}: ${event.Body}`, {
          to: '+13105555555'
      });
      callback(null, twiml);
      };
  6. Configure this Function on your Twilio number by following the steps here: Configuring phone numbers to receive calls or SMS messages.

SMS Message Forwarding with Webhooks

Webhooks allow you to host your own TwiML from a simple XML script or one of our Helper Libraries. For more information on Webhooks, please see our page here: What is a Webhook.

Recommended for: Twilio users who want a completely customizable Twilio application.

Set up: Setting up a Webhook requires you to create your code with the <Message> Verb, including the “to” attribute for your target phone number for receiving forwarded SMS messages, and then posting it to your own server. Here's an example of how this code may look using PHP:

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

Once your code is live, you’ll then need to update your Twilio phone number with the Webhook URL for handling incoming SMS messages. You can find instructions for updating your phone number here: Configuring phone numbers to receive calls or SMS messages.

How Much Does this Cost?

When forwarding SMS Messages, you will be charged for both the incoming message, and the outgoing message. These prices may vary, depending on the phone number type, and outbound message destination. For complete details, please see our SMS Pricing site.

 

Have more questions? Submit a request
Powered by Zendesk