title: PHP contact form handler not working?
body: <p>I need a very simple, but effective PHP form handler that will work with this form:</p>
  
  <pre><code>&lt;form id="contact" method="post" action="contact_handle.php"&gt;
  &lt;label for="name"&gt;Name:&lt;/label&gt;
  &lt;input type="text" class="text_style" placeholder="John Doe" name="name" /&gt;&lt;br /&gt;
  &lt;label for="email"&gt;Email:&lt;/label&gt; 
  &lt;input type="email" class="text_style" placeholder="email@example.com" name="email" /&gt;&lt;br /&gt;   
  &lt;label for="message"&gt;Subject:&lt;/label&gt;
  &lt;textarea class="areawidth" rows="4" name="message" /&gt;&lt;/textarea&gt;&lt;br /&gt;
  &lt;button id="contactbutton" type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;  
  </code></pre>
  
  <p>This is what I currently have but it doesn't send an email and it doesn't redirect like I intended. And I cant seem to figure out whats going on.</p>
  
  <pre><code>&lt;?php  
  $invalid = '';
  $my_email = 'my@email.com'; 
  
  // Validate input:
  if(empty($_POST['name'])  ||
     empty($_POST['email']) ||
     empty($_POST['message']))
  {
      $invalid.= "\n All fields are required";
  }
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];   
  
  // Validate email:
  if (!preg_match(
  "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
  $email))
  {
      $invalid .= "\n Invalid email address";
  }
  
  // Send email if no errors detected:
  if( empty($invalid))
  {
  $to = $my_email;
  $subject = "Contact form submission: $name";
  $body = "You have received a new message. ".
  " Here are the details:\n Name: $name \n ".
  "Email: $email\n Message:\n $message";
  $headers = "From: $email\n";
  $headers .= "Reply-To: $email";
  mail($to,$subject,$body,$headers);  
  
  //redirect to the thank you page:    
  header('Location: contact_thanks.php');
  }
  ?&gt;    
  </code></pre>
  
  <p>When it is submitted it takes me to contact_handle.php that displays blank and fails to redirect. </p>