<?php
date_default_timezone_set('Asia/Kolkata');
include_once("include/main.inc.php"); 
date_default_timezone_set('Asia/Kolkata');
$date=date('Y-m-d H:i');

 @extract($_POST);
// print_r($_POST);
// exit;

$admin_sql=mysqli_query($dbconn,"select * from admin_details");
$admin_res=mysqli_fetch_array($admin_sql);

$referer = $_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];

  if(strpos($en_message,'#')!==false || strpos($en_message,'%')!==false || strpos($en_message,'@')!==false || strpos($en_message,'&')!==false || strpos($en_message,'~')!==false || strpos($en_message,'https')!==false || strpos($en_message,'http')!==false || strpos($en_message,'www')!==false || strpos($en_message,'?')!==false){
      $res ='<div class="alert alert-danger alert-dismissible  show">URL(s) and special characters are not allowed <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
  } else {   
if($user_name!='' &&  $email_address!='' && $phone_no!='' && $locations!='' && $en_message!=''){
    
  if (filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
if(strlen($phone_no)==10){

$secret = '6Lf6jT0iAAAAAEapAXKmph4SQwiH24I7sTcF6h_3';
 $data = array( 'secret' => $secret, 'response' => $_POST['g-recaptcha-response'] ); $verify = curl_init(); curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify"); curl_setopt($verify, CURLOPT_POST, true); curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($verify); //var_dump($response);
        $response = json_decode($response);  
if($response->success)
{
    
$sql_ens = "insert into tbl_enquiry set en_name='$user_name', en_email='$email_address', en_mobile='$phone_no', en_country='$locations', en_comment='$en_message', en_url='$referer', en_date='$date', en_ip='$ip'";
   
   $qry = mysqli_query($dbconn,$sql_ens);
        

$subject = utf8_encode('Webpulseindia.com '.' - '. $admin_res['subject']);
$htmlContent = "
Customer Details:

Url: $referer

Your Name: " . $user_name . "

Mobile: " . $phone_no . "

Email: " . $email_address . "

Location: " . $locations . "

Message: " . $en_message . "
";
             
$to =  $admin_res['email'];
$to2 = $admin_res['cc'];
$to3 = $admin_res['bcc'];
 
		
    $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
            'Reply-To:  '.$user_name.'<'.$email_address.'>' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
            @mail($to,$subject,$htmlContent,$headers);
            @mail($to2,$subject,$htmlContent,$headers);
            @mail($to3,$subject,$htmlContent,$headers);
    
        $res = '<div class="alert alert-success alert-dismissible  show">Your Enquiry has been sent successfully. Our Team will contact you shortly!<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
     $user_name='';
            $phone_no='';
            $email_address='';
            $locations='';
            $en_message='';
              

}
    else{
      $res = '<div class="alert alert-danger alert-dismissible show">Please verify you are human by filling out the captcha <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';  
    }
}
    else{
        $res = '<div class="alert alert-danger alert-dismissible  show">Please Enter 10 Digit Mobile Number. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
    }
    }
    else{
       $res = '<div class="alert alert-danger alert-dismissible  show">Invalid Email Format <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';  
    }
}
        else {
                $res = '<div class="alert alert-danger alert-dismissible  show">Asterisk(*) Marked fields are Mandatory. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
        }
    }
  
    echo $res;
    
?>
