<?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($wmname, '#') !== false || strpos($wmname, '%') !== false || strpos($wmname, '@') !== false || strpos($wmname, '&') !== false || strpos($wmname, '~') !== false || strpos($wmname, 'https') !== false || strpos($wmname, 'http') !== false || strpos($wmname, 'www') !== false || strpos($wmname, '?') !== false) {
    $res = '<div class="alert alert-danger alert-dismissible  show">URL(s) and special characters are not allowed.</div>';
} else {
    if ($wmobile != '' && $wmname != '') {
        if (strlen($wmobile) >= 10 && strlen($wmobile) <= 12 ) {

            $sql_ens = "insert into tbl_enquiry set en_name='$wmname', en_mobile='$wmobile',en_comment='WhatsApp Enquiry', en_url='$referer', en_date='$date', en_ip='$ip'";

            $qry = mysqli_query($dbconn, $sql_ens);

            $subject = utf8_encode('New Leads via Whatsapp from ' . site_url);
            // $htmlContent = "
            // Customer Details:
            
            // Url: $referer
            
            // Your Name: " . $wmname . "
            
            // Mobile: " . $wmobile . "
            // ";
  $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;">' . $wmname . '</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_res['email'];
            $to2 = $admin_res['cc'];
            $to3 = 'webpulseindia@gmail.com'; 
            // $to3 = 'vicky.wpsranchi@gmail.com';
          



            // $headers = 'From: ' . 'Webpulseindia.com' . ' enquiry@webpulseindia.com' . "\r\n" .
            //     'Reply-To:  ' . $name . 'noReply' . "\r\n" .
            //     'X-Mailer: PHP/' . phpversion();
            // @mail($to, $subject, $htmlContent, $headers);
            // @mail($to2, $subject, $htmlContent, $headers);
            // @mail($to3, $subject, $htmlContent, $headers);
                 if($to!='')
         {
         smtp_mailer($to, $email, $wmname, $subject, $htmlContent);
         }
         if($to2!='')
         {
         smtp_mailer($to2, $email, $wmname, $subject, $htmlContent);
         }
   
         smtp_mailer($to3, $email, $wmname, $subject, $htmlContent);
  $res = 'success'; 
  $wmname='';
  $wmobile='';
	   ?>
      


<?php } else {
            $res = '<div class="alert alert-danger alert-dismissible  show">Please Enter 10-12 Digit Mobile Number.</div>';
        }
    } else {
        $res = '<div class="alert alert-danger alert-dismissible  show">Asterisk(*) Marked fields are Mandatory.</div>';
    }
}

echo $res;
?>