You can include line breaks in your messages sent from Twilio. 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.
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
Sending an Outbound Message without a Helper Library via the REST API
When sending outbound messages via the REST API without using a helper library, it is best to encode a new line character using URL encoding. In URL encoding, a new line character is encoded as
Here’s an example cURL script:
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \ -d "To=+13105551234" \ -d "From=+12125555555" \
-d "Body=Here is my first line%0aHere is my second line" \
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>
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.