Reputation: 271
I've been trying to get a new line generated in my SMS message sent from a PHP script. I've used \r\n
, <BR>
and some hex codes. No matter what I do the message comes to my phone without line breaks.
$body .= 'City:'.$venue.'\r\n'; //<- doesn't work
$body .= 'State:'.$state.'<br>'; //<- doesn't work
This is my header type...(complete header not included)
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
I use mail to send...
mail($somenumber,$subject,$body,$headers)
Everything works fine in the sense that I receive the message. I hope that I'm missing something, because this is driving me crazy.
Upvotes: 27
Views: 63701
Reputation: 43
I've been trying to figure out how to fix this and if you are using phpmailer, setting the isHtml(false) fixed my issue and made my <br become a line break on my innerText.
$mail->isHTML(false);
Upvotes: 0
Reputation: 109
This worked for me in php,
$message = "Welcome,
some text
Thank you for choosing us.";
Upvotes: 2
Reputation: 437
Had same problem, this works for me.
$text .= chr(10) . 'hello world'; But all other answer didn't when i tested.
Upvotes: 2
Reputation: 33605
for me sometimes %0a
works and sometimes \n
works depends on the SMS gateway
Upvotes: 6
Reputation: 91
Try "\n" instead of '\n';
Because in single quotes it take the character as it is.
Example:
echo nl2br('one \n two');//print: one \n two
echo nl2br("one \n two");//print: one <br> two
Upvotes: 3
Reputation: 703
Let the ascii do the work for you. ASCII character 10 is the carriage return. This worked for me on Android.
$body = 'City:' . $city;
$body .= chr(10) . 'State:' . $state;
$body .= chr(10) . 'Zip:' . $zip;
Upvotes: 0
Reputation: 533
You have to understand how that message is encoded to be sent. For my situation, using routosms api, I had to disable their api's use of urlencode(using php) on my message string. Then, %0A worked.
Upvotes: 1
Reputation: 21
Use \r\n
and then encode it using urlencode()
. It worked on Android
Upvotes: 2
Reputation: 1
Just a little bit of code helps the medicine go down. I forgot an important little piece of code:
Content-Transfer-Encoding: 7bit
You need the code above added to your header. HTH.
Upvotes: 0
Reputation: 44
'\n' will print two characters: \ and n
"\n" will print a line feed character (0x0A)
Upvotes: 27
Reputation: 98469
You are setting the content type as text/html. Try sending a <br/>
. HTML is whitespace-agnostic and uses the break tag to force a new line.
If you don't want the message to be HTML, don't mark it as such.
Upvotes: 0