Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kaeckisthename

macrumors member
Original poster
Aug 22, 2007
48
0
I am designing a website for Grocery Pick Up and Delivery service. I created a form with all the necessary input areas (name, address, delivery time, etc.)

I am trying to use PHP to collect the data of the form and email it to a specified email address.

I have the message sending correctly, but it is a blank message that is sent.

What I'm asking is......Is there a way to collect the ENTIRE FORM including all fields and email it. Or do I have to specify each individual field to collect

here is the PHP I have...

Code:
<?php
   } else {
      error_reporting(0);
      $recipient = 'dkaeck@corsp.org';
      $subject = "Order Form";
      $from = stripslashes($_POST['Name']);
      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
	  $headers = "MIME-Version: 1.0\r\n";
      $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";$headers = "MIME-Version: 1.0\r\n";
      $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
	  $headers.= "From: $from\r\n";
      if (mail($recipient, $subject, $msg, $headers))
         echo nl2br("<b>Your Order Has Been Sent</b>
         To: $recipient
         Subject: $subject
         Message: Attached Order Form
         $msg");
      else
         echo "Your Order Failed To Send";
}
?>

I'm guessing that this part of the code is where the form or fields should be listed for submission.

Code:
$msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
 
Yes you need to collect from each form field and make it part of the message that get emailed, none of that happens automatically. The form fields are accessed through the $_POST[] array and you access it by the form fields name attribute.
 
Okay, I kinda guessed that....I'm new to php and trying to learn a little bit

Another Question...

On this section here....
Code:
$msg = "Message from: $from\n\n".stripslashes($_POST['Name']).stripslashes($_POST['email']);
How do I insert line breaks between the $_POST elements....I've tried the nl2br and \n but I get an error

your help is very much appreiated
 
Okay, I kinda guessed that....I'm new to php and trying to learn a little bit

Another Question...

On this section here....
Code:
$msg = "Message from: $from\n\n".stripslashes($_POST['Name']).stripslashes($_POST['email']);
How do I insert line breaks between the $_POST elements....I've tried the nl2br and \n but I get an error

your help is very much appreciated

For readability I have often done,

PHP:
$msg = "Message from: $from

stripslashes($_POST['Name'])\nstripslashes($_POST['email'])";

Just typing in the new lines where needed since it'll read the string across lines in your PHP. Though the \n should also be working.
 
For readability I have often done,

PHP:
$msg = "Message from: $from

stripslashes($_POST['Name'])\nstripslashes($_POST['email'])";

Just typing in the new lines where needed since it'll read the string across lines in your PHP. Though the \n should also be working.

the values are still running as one line with no breaks on output
 
I find it best & easiest to maintain if you post form data and assign them to variables, the perform the mail() function. Here's a sample...

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$order = $_POST['order'];


$to = "dkaeck@corsp.org";
$from = "From: $name <$email>";
$subject = "Order";
$message = "Name: $name\nEmail: $email\nOrder: $order\n";

mail($to,$subject,$message,$from);


echo "<h1>Success</h1>";
echo "<p>We've received your order</p>";

?>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.