<html>
  <head>
<?php
// Google reCaptcha secret key
$secretKey  = "6LeFVMsZAAAAAAJMnR3YZQYi2HkSH8IkWwH0mNHF";

$statusMsg = '';

if(isset($_POST['submit2'])){
    if(isset($_POST['captcha-response2']) && !empty($_POST['captcha-response2'])){
        // Get verify response data
        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['captcha-response2']);
        $responseData = json_decode($verifyResponse);
        if($responseData->success){
            //Contact form submission code goes here ...  
            $statusMsg = 'Your contact request have submitted successfully.';

//Email Verification Starts HERE
function tep_validate_ip_address($ip_address) {
    if (function_exists('filter_var') && defined('FILTER_VALIDATE_IP')) {
      return filter_var($ip_address, FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV4));
    }
    if (preg_match('/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $ip_address)) {
      $parts = explode('.', $ip_address);
      foreach ($parts as $ip_parts) {
        if ( (intval($ip_parts) > 255) || (intval($ip_parts) < 0) ) {
          return false; // number is not within 0-255
        }
      }
      return true;
    }
    return false;
  }
  function tep_get_ip_address() {
    $ip_address = null;
    $ip_addresses = array();
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
      foreach ( array_reverse(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) as $x_ip ) {
        $x_ip = trim($x_ip);
        if (tep_validate_ip_address($x_ip)) {
          $ip_addresses[] = $x_ip;
        }
      }
    }
    if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) {
      $ip_addresses[] = $_SERVER['HTTP_CLIENT_IP'];
    }
    if (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && !empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
      $ip_addresses[] = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
    }
    if (isset($_SERVER['HTTP_PROXY_USER']) && !empty($_SERVER['HTTP_PROXY_USER'])) {
      $ip_addresses[] = $_SERVER['HTTP_PROXY_USER'];
    }
    $ip_addresses[] = $_SERVER['REMOTE_ADDR'];
    foreach ( $ip_addresses as $ip ) {
      if (!empty($ip) && tep_validate_ip_address($ip)) {
        $ip_address = $ip;
        break;
      }
    }
    return $ip_address;
  }  
  function tep_validate_email($iddemail) {
  define('ENTRY_EMAIL_ADDRESS_CHECK', 'true');
    $iddemail = trim($iddemail);
    if ( strlen($iddemail) > 255 ) {
      $valid_address = false;
    } elseif ( function_exists('filter_var') && defined('FILTER_VALIDATE_EMAIL') ) {
     $valid_address = (bool)filter_var($iddemail, FILTER_VALIDATE_EMAIL);
    } else {
      if ( substr_count( $iddemail, '@' ) > 1 ) {
        $valid_address = false;
      }
      if ( preg_match("/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i", $iddemail) ) {
        $valid_address = true;
      } else {
        $valid_address = false;
      }
    }
    if ($valid_address && ENTRY_EMAIL_ADDRESS_CHECK == 'true') {
      $domain = explode('@', $iddemail);
      if ( !checkdnsrr($domain[1], "MX") && !checkdnsrr($domain[1], "A") ) {
        $valid_address = false;
      }
    }
    return $valid_address;
  } 

 if(isset($_POST['iddemail'])) {

	
require 'mail/PHPMailerAutoload.php';
 $mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output


$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.nbtgains.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'info@nbtgains.com';                 // SMTP username
$mail->Password = 'Innbt$#753@';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->From = 'info@nbtgains.com';
$mail->FromName = 'Nbt Gains';
$mail->addAddress('nayyannbthakker@gmail.com', 'NBT Gains');     // Add a recipient
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'NBT Gains Inquiry';
$iddnames = $_POST['iddname'];
$iddemails = $_POST['iddemail'];
// $iddhows = $_POST['iddhow'];
// $iddphones = $_POST['iddphone'];
$iddsubjects = $_POST['iddsubject'];
$iddmessages = $_POST['iddmessage'];
$mail->Body = 'Hello,<br/><br/>We have received a new inquiry with following details:<br/><br/>Name: '.$iddnames.'<br/>Email: '.$iddemails.'<br/>Subject: '.$iddsubjects.'<br/>Message: '.$iddmessages.'<br/><br/>Thank You';

if($mail->send()) {
    $sent_mail = true;
?>
    
<!-- place your own success html below -->

    <script type="text/javascript">
      alert("Email Sent");window.location.href='index.html';
    </script>

<?php
} else {
    $sent_mail = false;
?>
<!-- place your own success html below -->
    <script type="text/javascript">
      alert("Error");window.location.href='index.html';
    </script>
 
			<?php
        }
     }   
    }    
        else{
            $statusMsg = 'Robot verification failed, please try again.';
            ?>

    <script type="text/javascript">
      alert("Robot verification failed, please try again.");window.location.href='index.html';
    </script>
    
<?php
        }
    }
    else
    {
        $statusMsg = 'Robot verification failed, please try again.';
        
                    ?>
     
            <script type="text/javascript">
              alert("Robot verification failed, please try again.");window.location.href='index.html';
            </script>
          

        <?php
    }
    }
    die();
?>
  </head>
  <body></body>
</html>
