title: How to redirect to success / fail pages after php form submission?
body: <p>I have successfully integrated the following form submission code into my site, and it works great. However I would like to have the code redirect the user to one page if the form submission is successful, and a different page if it fails. How could I adapt the following code to do that? It's really starting to get on my nerves! :-P</p>
  
  <pre><code>&lt;?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $enquiry = $_POST['enquiry'];
  $formcontent=" From: $name \n Phone: $phone \n Message: $enquiry";
  $recipient = "email@email.co.uk";
  $subject = "Contact Form";
  $mailheader = "From: $email \r\n";
  mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
  echo "Thank You!";
  ?&gt;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Ok I have changed the code to:</p>
  
  <pre><code>&lt;?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $enquiry = $_POST['enquiry'];
  $formcontent=" From: $name \n Phone: $phone \n Message: $enquiry";
  $recipient = "email@email.co.uk";
  $subject = "Contact Form";
  $mailheader = "From: $email \r\n";
  if(mail($recipient, $subject, $formcontent, $mailheader)){
  header("Location: mailer-success.htm");
  }else{
  header("Location: mailer-fail.htm");
  }
  exit;
  ?&gt;
  </code></pre>
  
  <p>This works however it never goes to the fail page. I'm guessing that's because the email is always sent even if fields are empty. I have jquery verification in place (which I have disabled for testing purposes) but that obviously only works for users with javascript enabled. How could I alter the code to only show the success page if the form fields contain data? Any help is appreciated.</p>