SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

How do I add a line break in my SMS or MMS message?

Objective

This is a guide on how to include line breaks in your messages sent from Twilio.

 

Product

Programmable Messaging

 

User Account Permission/Role(s) Required

Owner, Developer

 

Procedure

Sending an Outbound Message with one of our Helper Libraries

If you are using one of the official Twilio helper libraries to send SMS messages, you can use new lines encoded in strings as \n.

 

Sending an Outbound Message without a Helper Library using cURL

When sending API requests using cURL, you can insert a dollar sign $ before your Body parameter in your request. This will cause any escape characters in the Body parameter to be encoded. The escape character \n will result in a newline character (line break).

In your cURL request, make sure to enclose your Body parameter in single quotes, not double quotes.

Here’s an example cURL script:

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
--data-urlencode 'To=+13105551234' \
--data-urlencode 'From=+12125555555' \
--data-urlencode $'Body=Here is my first line\nHere is my second line' \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'

This example sends an outbound message from the sender (212) 555-1234 (+12125551234) to the recipient at (310) 555-5555 (+13105555555), and includes the following message:

Here is my first line
Here is my second line

To make this script work for you, make the following updates, and then paste it into a terminal window:

  • Line 1 update with your Account SID
  • Line 2 update with a valid destination
  • Line 3 update with a valid sender number
  • Line 4 update with the desired message text
  • Line 5 update with your Account SID and Auth Token

 

Replying to an Incoming Message via TwiML

In a TwiML reply, you can insert a line break by just using a new line.

Here’s an example TwiML script:

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

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

 

Additional information 

You may need to encode the line break differently in your code, depending on whether you are using one of our official Twilio helper libraries.

Have more questions? Submit a request
Powered by Zendesk