<?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_data=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",$wname)){  
if($wname!='' &&  $wmobile!='' && $ip!='' ){
if(strlen($wmobile)==10){
 $sql_ens = "insert into tbl_enquiry set en_name='$wname', en_mobile='$wmobile', en_url='$referer', en_date='$date', en_ip='$ip'";
$qry = mysqli_query($dbconn,$sql_ens);
//      print_r($qry);
//  print_r($_POST);
//exit; 
$subject = utf8_encode('Webpulseindia.com '.' - Whatsapp '. $admin_data['subject']);
$htmlContent = "
Customer Details:

Url: $referer

Your Name: " . $wname . "

Mobile: " . $wmobile . "

Posted URl: " . $referer . "

";
 $to =  $admin_data['email'];
$to3 = $admin_data['bcc'];

    
     $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
            'Reply-To:  '.$wname.'<'.$email_address.'>' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
    
	       @mail($to,$subject,$htmlContent,$headers);
			@mail($to3,$subject,$htmlContent,$headers);
          

	   $res = '<div class="alert alert-success">Whatsapp Enquiry Submitted successfully.  Our Team will contact you shortly!</div>';?>
        
	   <script>
                window.open('https://api.whatsapp.com/send?phone=917298666555&text=I <?php echo $wname;?>,I was on your Website (<?php echo $referer;?>) and i am interested in your Products&source=&data="'); 
</script>
<?
}
    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">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">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;
    
?>