How do I Add a Line Break in my SMS or MMS Message?

When sending an SMS or MMS message from Twilio, new line encoding may vary slightly, depending on the terminating wireless carrier. The following are the methods that we find work most consistently for the different types of SMS messages you can send.

Sending an Outbound Message via the REST API

When sending outbound messages via the REST API, it is best to encode a new line as %0a.

Here’s an example cURL script:

curl -XPOST \
-d "To=+13105551234" \
-d "From=+12125555555" \
-d "Body=Here is my first line%0aHere is my second line" \

To make this script work, update line 1 with your Twilio Account SID, lines 2 and 3 with valid phone numbers, and line 5 with your Account SID and Auth Token. Once your script is updated, paste it into a terminal window.

If you are using one of the official Twilio helper libraries to send SMS messages, they will take care of encoding new lines present in strings as \n.

Replying to an Incoming Message via TwiML

In a TwiML reply, the best way to insert a line break is to just use a new line. 

Here’s an example TwiML script:

<?xml version="1.0" encoding="UTF-8"?>
    <Sms>Here is my first line.
Here is my second line.</Sms>

These examples should deliver a message with “Here is my first line” on line one, and then “Here is my second line” on line two.

Have more questions? Submit a request
Powered by Zendesk