<?php
    session_start();
    echo $_POST["email"];
    $name = $_POST['name'];
    if(isset($_POST['email'])) {
      $email_to = "";
      $email_subject = "Email from customer(".$name.")";

      $name = $_POST['name'];
      $email_from = $_POST['email'];
      $telephone = $_POST['telephone'];
      $comments = $_POST['comments'];

      $_SESSION['name'] = $name;
      $_SESSION['email'] = $email_from;
      $_SESSION['telephone'] = $telephone;
      $_SESSION['comments'] = $comments;
      $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email_from)) {
    $_SESSION['message'] = 'The Email Address you entered does not appear to be valid.<br />';
    header("Location: http://77.96.72.99:1111/Index#ContactUs");
  }
    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$name)) {
    $_SESSION['message'] = 'The Name you entered does not appear to be valid.<br />';
    header("Location: http://77.96.72.99:1111/Index#ContactUs");
  }

      $email_message = "Customer information .\n\n";

  function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);

  }

    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Message: ".clean_string($comments)."\n";

    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();

    if(!preg_match($email_exp,$email_from)) {
    }else{
     if(!preg_match($string_exp,$name)) {

     }else{
        @mail($email_to, $email_subject, $email_message, $headers);
        $_SESSION['message'] = 'Thanks for contacting us! We will get in touch with you shortly.<br />';
        header("location: http://77.96.72.99:1111/Index#ContactUs");
    }
  }
?>

<?php
}
?>
