<?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_url='$referer', en_date='$date', en_ip='$ip'";
$qry = mysqli_query($dbconn,$sql_ens);
//      print_r($qry);
//  print_r($_POST);
// exit; 
$name = $wname;
    $email = 'enquiry@webpulseindia.com';

 $subject = utf8_encode('New Leads via Whatsapp from '.site_url);
        $htmlContent =  '<table border="0" width="100%">
        <tbody>
  <tr>
    <td colspan="2">
      <strong>Dear Admin</strong></td>
  </tr>
  <tr>
    <td colspan="2">
      Enquiry Received with following info :</td>
  </tr>
  <tr>
    <td colspan="2">
      &nbsp;</td>
  </tr>
  <tr>
    <td width="26%">
      <strong>Post URL : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $referer . '</span></td>
  </tr>
   <tr>
    <td width="26%">
      <strong>Name : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $name . '</span></td>
  </tr>

 
 <tr>
    <td width="26%">
      <strong>Contact No : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $wmobile . '</span></td>
  </tr>

</tbody>
       
        </table>';
 $to =  $admin_data['email'];
$to2 = $admin_data['cc'];
$to3 = $admin_data['bcc'];
// $to3 = 'vicky.wpsranchi@gmail.com';

	   if($to!='')
         {
         smtp_mailer($to, $email, $name, $subject, $htmlContent);
         }
         if($to2!='')
         {
         smtp_mailer($to2, $email, $name, $subject, $htmlContent);
         }
        
         smtp_mailer($to3, $email, $name, $subject, $htmlContent);
        

	   $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=919212168851&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;
    
?>