I have a PHP webshop that automatically sends a confirmation email. Below is part of the script. My problem is that the line breaks do not work. In MS Outlook the text appears as one long line. I tried things like \n, \r\n, <br>\n, but non worked. How can I solve this?
In fact, the line breaks sometimes work, and sometimes not. The result will look something like this:
ATACAMA DESERT - SALTA
= Ojos del Salado - 1:75.000
CENTRAL ANDES - MENDOZA
= Aconcagua - 1:100.000
3 = Aconcagua - 1:50.000
= Cordón del Plata - 1:50.000
= Paloma & El Plomo - 1:50.000
= Volcán San José & Cajón del Maipo - 1:50.000 LAKES DISTRICT - BARILOCHE = Comarca Andina del Paralelo 42° - 1:120.000
1 = Tronador & Paso de las Nubes - 1:50.000 = Parque Nacional Los Alerces - 1:120.000 = Ruta de los Siete ***** - 1:125.000 = San Carlos de Bariloche - 1:50.000 = San Carlos de Bariloche & Alrededores - 1:125.000
Maybe I should explain a bit more. The email sent is a plain text message, and not a HTML email. I've found plenty of threads on line breaks in HTML mail, but none gave the answer on a plain text email.
I feel your pain and been through it before. Outlook has a nasty habit of removing what it thinks is "extra line breaks" in plain text emails. Sometimes, if the recipient is saavy enough they can choose to restore line breaks from the messages options. This is hardly practical, but it will get you a decent printout.
I've only found a few solutions to making email universally compatible with Outlook.
Send the message as html
Use double line breaks (\n\n)
Just out of curiosity, are you on version 2003?
The attachment shows an illustration of this problem. by clicking on the bar you can choose to restore the line breaks
HTML mail has the disadvantage that not all email clients exept it.
Your \n\n solution will start a new paragraph with every line. So it works, but just not quite...
I could, of course, use \n\n only for those line breaks that fail using just \n. But can I be sure this gives the same results on all email clients, including webmail?
I think I found the solution, thanks to Hastx's suggestion of Outlook behavior. I just added a dot (.) at the end of every line. This way Outlook WILL understand a line break makes sense.
HTML mail has the disadvantage that not all email clients exept it.
The standard way to work with this is to send two parts - plain text and mime. If the client can read a mime formatted mail it does so. Otherwise it displays the plain text.
To learn more search for "creating plain text and mime formatted email with php".
Thanks Taschen for your reply. I know a HTML mail should also have a plain text part. That means that this Outlook bug on plain text should be solved anyway, whether you use HTML or not.
Bookmarks