PHP feedback form

I’m using this code to process a feedback form;

<?php
   if ($_SERVER['REQUEST_METHOD'] != 'POST'){
      $me = $_SERVER['PHP_SELF'];
?>

... Form goes here ...

<?php
   } else {
      error_reporting(0);
      // initialize a array to 
      //hold any errors we encounter
      $errors = array();
      // test to see if the form was actually 
      // posted from our form
      $page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
      if (!ereg($page, $_SERVER['HTTP_REFERER']))
         $errors[] = "Invalid referer<br>
";
	  // check to see if a name was entered
      if (!$_POST['Name'])
         $errors[] = "<p>Please enter a value in the <b>Name</b> field.</p>";
		 // check to see if a email was entered
      if (!$_POST['Email'])
         $errors[] = "<p>Please enter a value in the <b>Email</b> field.</p>";
	  // check to see if a Telephone was entered
      if (!$_POST['Telephone'])
         $errors[] = "<p>Please enter a value in the <b>Telephone</b> field.</p>";
	  // if there are any errors, display them
      if (count($errors)>0) {
         foreach($errors as $err)
            echo "$err
";
         echo "<p>Please use your browser's Back button to enter your details into the correct fields.</p>";
      } else {
         // no errors, so we build our message 
      $recipient = 'email@address.com';
	  $subject = "Contact";
      $email = stripslashes($_POST['Email']);
      $from = stripslashes($_POST['Name']);
	  $msg ="Below is the detail submitted through the Contact Form: 
";
	  $msg.="
Name: ". $_POST['Name'];
	  $msg.="
E-mail address: ". $_POST['Email'];
	  $msg.="
Comany Name: ". $_POST['Company'];
	  $msg.="
Telephone Number: ". $_POST['Telephone'];
	  $msg.="

Interested in: ". $_POST['Interest'];
      $msg.="

Message: ".stripslashes($_POST['Message']);
	  $msg.="

Thank you.";
      $mailheaders = "From: $_POST[Email] 
";
	  $mailheaders .= "Reply-To: $_POST[Email]";
      if (mail($recipient, $subject, $msg, $mailheaders))
         echo "<p><b>Replace this to get thank you message on the webpage.</b></p";
      else
         echo "Message failed to send";
}
}
?>

How can I get this PHP to send a 2nd email as a ‘thank you for contacting us’ responder to the person who filled in the form??

... if (mail($recipient, $subject, $msg, $mailheaders) && mail($_POST['Email'], "thank-you-message-subject", "thank-you-message", "headers")) ...

Nice one, thanks loads - worked like a charm!!

Careful that code has a header injection vulnerability

yup.

you have to validate the input data :smiley:

thanks λ