title: Using HTML and PHP to send form data to an email
body: <p>Like the title says, sending a form to my email. I get no errors, but the email never comes. Here's my HTML form (I don't think you'll need anything else, but there is also some formatting and Java verification in the file).</p>
  
  <pre><code>&lt;form method="POST" name="contactform" action="contact-form-handler.php"&gt;
      &lt;p&gt;
          &lt;label for='name'&gt;Your Name:&lt;/label&gt;
          &lt;br&gt;
          &lt;input type="text" name="name"&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label for='email'&gt;Email Address:&lt;/label&gt;
          &lt;br&gt;
          &lt;input type="text" name="email"&gt;
          &lt;br&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label for='message'&gt;Message:&lt;/label&gt;
          &lt;br&gt;
          &lt;textarea name="message"&gt;&lt;/textarea&gt;
      &lt;/p&gt;
      &lt;input type="submit" value="Submit"&gt;
      &lt;br&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And here's my PHP. Obviously I took my email out and put in EMAIL instead, but other than that this is my complete PHP file. The thank you PHP file pulls up the submitted page just fine, and I get no errors. Just no email either.</p>
  
  <pre><code>&lt;?php 
  $errors = '';
  $myemail = 'EMAIL@gmail.com';
  if(empty($_POST['name'])  ||
     empty($_POST['email']) ||
     empty($_POST['message']))
  {
      $errors .= "\n Error: all fields are required";
  }
  $name = $_POST['name'];
  $email_address = $_POST['email'];
  $message = $_POST['message'];
  if (!preg_match(
  "/ ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
  $email_address))
  {
      $errors .= "\n Error: Invalid email address";
  }
  if( empty($errors))
  {
      $to = '$myemail';
      $email_subject = "Contact form submission: $name";
      $email_body = "You have received a new message. ".
          " Here are the details:\n Name: $name \n ".
          "Email: $email_address\n Message \n $message";
      $headers = "From: $myemail\n";
      $headers .= "Reply-To: $email_address";
      mail($to,$email_subject,$email_body,$headers);
      //redirect to the 'thank you' page
      header('Location: contact-form-thank-you.html');
  }
  ?&gt;
  </code></pre>
  
  <p>Thanks ahead of time for any help you can provide! I can give the rest of my HTML file or my other PHP file if you need it, this is where all the real functionality lies though.</p>