www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Plain text email line breaks not working

  1. #1
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304

    Exclamation Plain text email line breaks not working

    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?

    PHP Code:
    $mailbody1 "First name      = $firstname\n";
    $mailbody1 .= "Last name      = $lastname\n";
    $mailbody1 .= "Gender         = $gender\n";
    $mailbody1 .= "E-mail         = $email\n"
    Cheers, Jochem

  2. #2
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    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


    Cheers, Jochem

  3. #3
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    Anyone out there who can help me out?

    Many thanks!
    Jochem

  4. #4
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    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.

    Many thanks!
    Jochem

  5. #5
    Join Date
    Mar 2007
    Location
    Orlando
    Posts
    670
    Is this a Unix or Linux server? If so, the try "\r\n".

  6. #6
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    Thanks for your reply!

    I'm not sure. Anyway, I tried that but it didn't solve the problem.

    cheers, Jochem

  7. #7
    Join Date
    Apr 2007
    Posts
    1

    Thumbs up Plain text email line breaks not working

    Hi joe,

    you may use \\n instead of \n or \r\n

    try it out now.

    chears,
    sivaequos

  8. #8
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    Hi sivaequos,

    I feel honored you spent your very first post on WD on this thread. Welcome to the forum!

    I tried your solution using \\n, but unfortunately it didn't work.

    According to my webhost, the server runs on Linux. They say the following:
    Code:
    Linux:   \n
    Windows: \r\n
    Mac:     \r
    Does that help you any further?

    cheers, Jochem

  9. #9
    Join Date
    May 2003
    Posts
    599
    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
    Attached Images Attached Images
    Last edited by hastx; 04-24-2007 at 08:29 PM.

  10. #10
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    Hastx, thanks for your contribution!

    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?

    cheers, Jochem

  11. #11
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    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.

    Testing it now...

    cheers, Jochem

  12. #12
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    It works!!

    Another interesting thing I discovered: you should not use HTML entities for the mailbody, as it will show the entity code and not the character.

  13. #13
    Join Date
    Sep 2006
    Location
    Europe
    Posts
    174
    Quote Originally Posted by jochem
    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".

  14. #14
    Join Date
    May 2003
    Posts
    599
    Quote Originally Posted by jochem
    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.
    If that solves it...you are my new hero. You know how much time it will save me to not have to code the messages in html?

  15. #15
    Join Date
    Nov 2003
    Location
    the Netherlands
    Posts
    304
    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.

    cheers, Jochem

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles