Q:

How to redirect to success / fail pages after php form submission? 

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
<? 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!"; 
? >

EDIT:
Ok I have changed the code to:
<? 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;
? >

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. 

A:

add a redirect to the page:
// Test to see if variables are empty:
if(!empty($name) && ! empty($email) && ! empty($phone) && ! empty($enquiry)){
    // Test to see if the mail sends successfully:
    if(mail($recipient, $subject, $formcontent, $mailheader)){
        header("Location: success.php");
    }else{
        header("Location: error.php");
    }
}else{
    header("Location: back_to_form.php");
}

A:

mail function returns true/false when succeeds/fails.  So it's rather simple:
if (mail($recipient, $subject, $formcontent, $mailheader)) {
    header('location: success.php');
} else {
    header('location: fail.php');
}

