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)

5+ Year Member

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)

10+ Year Member

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

10+ Year Member

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)

5+ Year Member

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