homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

New lines in mails generated by php

 7:30 pm on Oct 3, 2007 (gmt 0)


I was wondering how I can best create new lines in mails via php. Should I add \n to the message or <br>?




 7:38 pm on Oct 3, 2007 (gmt 0)

It depends on what you make the MIME type.

If you have ="text/html"

Then <br /> will work..

If you have ="text/plain"

Then typing returns into the code itself should do the job of adding space.


 7:48 pm on Oct 3, 2007 (gmt 0)

Adding \n will give you a line break in the source code if you have a html MIME type, but wont give you a visual break in the browser. Using <br /> will give you a visual break.


 11:50 pm on Oct 3, 2007 (gmt 0)

When making system-generated emails for my site (thanks for subscribing, etc) I usually set the body as a large text var like this:

$body = "Hello,
thanks for subscribing....

Also, may I mention that our forum is pack full of information....

More words here.....

Thanks again!



This method will generate a text email with line breaks wherever I put them in the $body var. It is easier to work with than "\n" and works on both HTML and plain text mail readers.

Hope that helps.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved