<?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);
$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(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$en_message)){  
if($user_name!='' &&  $email_address!='' && $phone_no!='' && $location!='' && $en_message!=''){

  if (filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
if(strlen($phone_no)==10){

$secret = '6LfgpbghAAAAAHolCg2Kh_jMQeEv62hOVzlf2SQG';
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);    
if($responseData->success)
{
$sql_ens = "insert into tbl_enquiry set en_name='$user_name', en_email='$email_address', en_mobile='$phone_no', en_country='$location', en_comment='$en_message', en_url='$referer', en_date='$date', en_ip='$ip'";
   
$qry = mysqli_query($dbconn,$sql_ens);
        

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

Url: $referer

Your Name: " . $user_name . "

Mobile: " . $phone_no . "

Email: " . $email_address . "

Location: " . $location . "

Message: " . $en_message . "
";
            
$to =  $admin_res['email'];
$to2 = "webpulseindia@gmail.com";
$to3 = "priyanka@aarnasystems.in";
$to4 = "ankita@aarnasystems.in";
// $to = 'developer.wpsrnc@gmail.com';

		
	  $headers = "MIME-Version: 1.0" . "\r\n";
             $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
            'Reply-To:  '.$first_name.'<'.$email_address.'>' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
	        @mail($to,$subject,$htmlContent,$headers);
			@mail($to2,$subject,$htmlContent,$headers);
			@mail($to3,$subject,$htmlContent,$headers);
            @mail($to4,$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="btn-close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true"></span></button></div>';
        
            $sname='';
            $smobile='';
            $semail='';
            $slocation='';
            $smessage='';
}
    else{
      $res = '<div class="alert alert-danger alert-dismissible show">Please verify you are human by filling out the captcha <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true"></span></button></div>';  
    }
    
}
    else{
        $res = '<div class="alert alert-danger alert-dismissible show">Please Enter 10 Digit Mobile Number. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true"></span></button></div>';
    }
    }
    else{
       $res = '<div class="alert alert-danger alert-dismissible show">Invalid Email Format <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true"></span></button></div>';  
    }
}
        else {
                $res = '<div class="alert alert-danger alert-dismissible show">Asterisk(*) Marked fields are Mandatory. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true"></span></button></div>';
        }
    }else{ 
         $res ='<div class="alert alert-danger alert-dismissible show">URL(s) and special characters are not allowed <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true"></span></button></div>';
         }
  
    echo $res;
    
?>