Page 1 of 1

Mailform help

Posted: Thu Jul 23, 2009 9:28 am
by crooms
For some reason the line breaks are not processed in the email.

Code: Select all

<?php
ini_set("sendmail_from", "example@btinternet.com");
$mailfrom = "example@btinternet.com";
$mailto = "example@btinternet.com";
$thanks = "thanks.php";
 
    foreach ($_POST as $key=>$value)
    {
    $mailtext .= '<b>' .$key. ':</b>  ' .$value.'<br> ';
    }
    $headers = 'From: '.$mailfrom.'
    Reply-to: '.$mailfrom.'
    Return-path: '.$mailfrom.'
    Content-type: text/html
 
';
mail($mailto, " Site enquiry", $mailtext, $headers);
header("location: $thanks");
 
 
?>
This outputs in the email as

Code: Select all

<b>name:</b>  test<br> <b>address:</b>  test<br> <b>email:</b>  est<br> <b>telephone:</b>  dsates<br> <b>spamcheck:</b>  ok<br> <b>enquiry:</b>  test<br>
I am taking over a web technicians role, and am a relative newbie.

Re: Mailform help

Posted: Thu Jul 23, 2009 10:04 am
by jayshields
For line breaks in non-HTML email you'll want to use the newline character, "\n". Make sure you include that character using double-quotes.

Re: Mailform help

Posted: Thu Jul 23, 2009 10:10 am
by akuji36
Hello

I do not see any line breaks in your code.

try adding

Code: Select all

br/
when you wish to add line break.

Use the forward slash after your br so it looks like: <br/>.

Re: Mailform help

Posted: Thu Jul 23, 2009 1:28 pm
by crooms
Thanks for the help.

I've tried <br/> and /n, it still just displays <br/> or /n instead of doing a line break. It is crazy, it seems correct but just spits it all out on one line.

Is there anything apart from the code that may be causing this, e.g. server settings, or the form which it is getting info from?

Re: Mailform help

Posted: Thu Jul 23, 2009 1:48 pm
by jayshields
It's backslash-n, not forwardslash-n. And remember it needs to be in double quotes, not single quotes. Here's an example:

Code: Select all

$body = "This is my email message body.\n\nThere's a line break above this line.";
$body = 'This is my email message body.' . "\n\n" . 'There is a line break above this line.'; //alternative

Re: Mailform help

Posted: Fri Jul 24, 2009 3:12 am
by crooms
Thankyou very much for helping a newbie. \n worked.