File: /var/www/nowruzgan.com/contact.php
<?php
// error_reporting(E_ALL);
// ini_set('display_errors', 'On');
// set_error_handler("var_dump");
$token = $_POST['token'];
$secret = '6LcZh9ggAAAAAAeBH_n5l0fplRsd3aoUM1NvAA3I';
$action = $_POST['action'];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
  'secret' => $secret,
  'response' => $token
);
$options = array(
  'http' => array(
    'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
    'method'  => 'POST',
    'content' => http_build_query($data)
  )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
  print 'error sending captcha data.';
  exit;
}
$result = json_decode($result);
if(!$result->success) {
  print 'Your captcha failed. No bots/ads allowed!';
  exit;
}
if(isset($_POST['email'])) {
  $email_to = "babak.vandad@gmail.com";
  $email_subject = "Contact form nowruzgan submission";
  if(!isset($_POST['email']) ||
    !isset($_POST['message'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted. Email and message are mandatory.');       
  }
  $name = $_POST['fname'].' '.$_POST['lname'];
  $email_from =  $_POST['email']; // required
  $message = $_POST['message']; // required
  $error_message = "";
  $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
  $email_message = "Form details below.\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 .= "message: ".clean_string($message)."\n";
  // create email headers
  $headers = "From: contact@nowruzgan.com\r\n".
  'Reply-To: '.$email_from."\r\n" .
  'X-Mailer: PHP/' . phpversion();
  $email_result = mail($email_to, $email_subject, $email_message, $headers);
  if(!$email_result) {
?>
    Sorry! Your message failed.
<?php }else{ ?>
    Thank you for contacting us. We will be in touch with you soon.
<?php
  }
}