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
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
Notice: 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
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"?> <Response> <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.