Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

New lines in mails generated by php



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

10+ Year Member


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)

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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)

WebmasterWorld Senior Member 5+ Year Member

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)

5+ Year Member

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.



Featured Threads

Hot Threads This Week

Hot Threads This Month