Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

New Line in Email PHP

How do I get new line in message variable

10:13 pm on Aug 28, 2007 (gmt 0)

New User

5+ Year Member

joined:Aug 28, 2007
votes: 0

I am trying, and have searched four hours, and tried various ways, but nothing seems to work. I have set up a form on my site using flash which sends information to php, which then sends on email of flash input information. I can get this to work fine, however I need to separate the message which is sent as this has various input variables. please see below.

$message = $_POST["address"] . $_POST["postcode"] . $_POST["telephone"] . $_POST["day"] . $_POST["month"] . $_POST["year"] . $_POST["source"] . $_POST["message"] . $_POST["name"];

mail($sendTo, $subject, $message, $headers);


When I get the email through all appears all on one line with no spaces, I need to separate each to a new line. Any help is much appreciated. Thanks.

12:18 am on Aug 29, 2007 (gmt 0)

Full Member

10+ Year Member

joined:June 24, 2004
votes: 0

Have you tried \n between your post variables?
6:18 pm on Aug 29, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:May 16, 2005
votes: 0

If you need a new line, add the following code at the point you want the line break:
" \n "

For example:
$_POST["address"]." \n ".$_POST["postcode"]." \n " .$_POST["telephone"]." \n ".$_POST["day"].$_POST["month"].$_POST["year"] ." \n ".$_POST["source"]." \n ".$_POST["message"]." \n ".$_POST["name"];

It's important to note that when using \n, you must have it in between double quotes (") not single quotes ('). The newline command will not work if you place it in between single quotes.

Correct: " \n "
Incorrect: '\n'


8:27 pm on Aug 29, 2007 (gmt 0)

New User

5+ Year Member

joined:Aug 28, 2007
votes: 0

JB, Did what you posted, works a treat. Excellent, many thanks for your help. Alan.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members