PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
crooms
Forum Newbie
Posts: 3 Joined: Thu Jul 23, 2009 9:22 am
Post
by crooms » Thu Jul 23, 2009 9:28 am
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.
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Thu Jul 23, 2009 10:04 am
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.
akuji36
Forum Contributor
Posts: 190 Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut
Post
by akuji36 » Thu Jul 23, 2009 10:10 am
Hello
I do not see any line breaks in your code.
try adding
when you wish to add line break.
Use the forward slash after your br so it looks like: <br/>.
crooms
Forum Newbie
Posts: 3 Joined: Thu Jul 23, 2009 9:22 am
Post
by crooms » Thu Jul 23, 2009 1:28 pm
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?
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Thu Jul 23, 2009 1:48 pm
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
crooms
Forum Newbie
Posts: 3 Joined: Thu Jul 23, 2009 9:22 am
Post
by crooms » Fri Jul 24, 2009 3:12 am
Thankyou very much for helping a newbie. \n worked.