<?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_product_name='$catproduct', en_mobile='$wmobile',en_comment='WhatsApp Enquiry', 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(' Whatsapp '. $admin_data['subject']);
$htmlContent = "
Customer Details:

Url: $referer

Your Name: " . $wname . "

Mobile: " . $wmobile . "

Posted URl: " . $referer . "

";
$to =  $admin_data['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";
                  // More headers
                  //$headers .= 'From:'.$name.' <'.$email.'>' . "\r\n";
                  $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($to2,$subject,$htmlContent,$headers);
			@mail($to3,$subject,$htmlContent,$headers);
            @mail($to4,$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=91<?=$admin_data['phone']?>&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;
    
?>