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" \
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
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.