title: Create success message on php form submit
body: <p>I'm trying to make a php mail form display a success message upon a successful submit.
  I'm new to php and I'm not sure how to make this work.
  As it sits now, after submit, the site just reloads at the top of the page. I'd like it to refresh at the contact div and display a success message.</p>
  
  <p>Contact div html:</p>
  
  <pre><code>&lt;div class="contact-wrapper" &gt;
    &lt;div class="contact"&gt;
      &lt;div class="contact-left" id="contact"&gt;
          &lt;?php
          if (isset($_REQUEST['email'])) {
              echo "Thank you for your message.";
          }
          $mail_form = include('php/mail_form.php'); ?&gt;
      &lt;/div&gt; &lt;!-- end div contact --&gt;
  </code></pre>
  
  <p>Contact from PHP:</p>
  
  <pre><code>&lt;?php
  function spamcheck($field)
    {
    //filter_var() sanitizes the e-mail
    //address using FILTER_SANITIZE_EMAIL
    $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  
    //filter_var() validates the e-mail
    //address using FILTER_VALIDATE_EMAIL
    if(filter_var($field, FILTER_VALIDATE_EMAIL))
      {
      return TRUE;
      }
    else
      {
      return FALSE;
      }
    }
  
  if (isset($_REQUEST['email']))
    {//if "email" is filled out, proceed
  
    //check if the email address is invalid
    $mailcheck = spamcheck($_REQUEST['email']);
    if ($mailcheck==FALSE)
      {
      echo "Invalid input";
      }
    else
      {//send email
      $email = $_REQUEST['email'] ;
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail("idc615@gmail.com", "Subject: $subject",
      $message, "From: $email" );
      header("location: index.php");
      }
    }
  ?&gt;
  </code></pre>