Log in

View Full Version : Really easy one: how to space form values in resulting email...



lilibirdy
01-06-2009, 11:39 PM
I finally got my form working - just one more niggle - How do I get the different bits of info on separate lines?? This isn't working!



function sendMail($name,$email,$phone,$message){

$subject = "Message from website";
$from = "From: $name <$email>\r\nReply-To: $email\r\n";
$header = "MIME-Version: 1.0\r\n"."Content-type: text/html; charset=iso-8859-1\r\n";
$content = "From: $name\r\n
Contact Number: $phone\r\n
Enquiry: $message\r\n";


$content = wordwrap($content,70);
mail(MAIL_TARGET,$subject,$content,$from.$header);

Nile
01-06-2009, 11:41 PM
Try running it under the nl2br function (http://us3.php.net/nl2br).
(The content of course)

lilibirdy
01-06-2009, 11:58 PM
I didn't know you could use <br> How silly of me..... Thanks mate :)

Nile
01-07-2009, 12:00 AM
You can use <br>, bur say for example someone puts:


Hello
My
Name
Is
Nile

If you were inserting it into a db or something, I think it would show up like this:


HelloMyNameIsNile

Now if you used the nlbr function, it would show up like this:


Hello<br>
My<br>
Name<br>
Is<br>
Nile<br>

JasonDFR
01-07-2009, 10:17 AM
If you want to avoid using html, you can do something like this:


if ( empty($errors) ) {

$to = "yourEmail";
$subject = "yourSubject";
$message = "From: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Message:\n\n";
$message .= wordwrap($textarea, 50, "\n");
$from = "From: <webmaster@yourwebsite.com>\n";

if ( mail($to, $subject, $message, $from) ) {
$success = true;
} else {
$errors[] = '<p>Sorry, there is a problem sending the form.</p>';
}