Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

newline in PHP email scripts

re: previous posts

11:39 am on Dec 15, 2008 (gmt 0)

New User

5+ Year Member

joined:Dec 15, 2008
votes: 0

Just browsing through older posts, I noticed the advice given regarding
the insertion of newline in PHP-generated email.
I have found that
often doesn't work with an Apache server.
This causes hours of frustration for anyone trying to figure why their
generated mail is always on one continuous line !
A better solution is always to use:

$messageText .= $messageText ."<br>";

for each line break needed.

Quite why the HTML tag works without breaking out of PHP is beyond
my ken, but it does, every time !


2:16 pm on Dec 15, 2008 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

Welcome to WebmasterWorld, chriseccles2.

I believe you are confused about two very different situations here. The mail headers do indeed require separation by newline, as per the mail RFC. Therefore, the

must be coded properly.

However, if you are sending out HTML formatted mail, the only way to get your content separated is to use block elements in your HTML that are going to "push" the next block of information below the previous. An alternative is to wrap your $messageText in a set of HTML <pre></pre> tags and code your newlines that way.

To summarize, there is a difference between coding the message headers and the message content (body) itself.

8:35 pm on Dec 21, 2008 (gmt 0)

New User

5+ Year Member

joined:Dec 21, 2008
votes: 0

"I have found that '\r\n' often doesn't work with an Apache server."

I have found that I need to use double quotes to make this work, that is use "\r\n"


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members