Trying to get new line on sms message sent from php script
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 开发者_C百科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.
Use: %0a
, worked for me in Nokia and Android
'\n' will print two characters: \ and n
"\n" will print a line feed character (0x0A)
for me sometimes %0a
works and sometimes \n
works depends on the SMS gateway
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
Use \r\n
and then encode it using urlencode()
. It worked on Android
Had same problem, this works for me.
$text .= chr(10) . 'hello world'; But all other answer didn't when i tested.
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.
This worked for me in php,
$message = "Welcome,
some text
Thank you for choosing us.";
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.
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.
Use double quotes, single quotes don't recognize new lines
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;
You can use PHP_EOL
for ending a line.
Use %0a , I think it will work
精彩评论