<?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'];
$code = (!empty($_POST['code']))?$_POST['code']:'';
$countryNames = (!empty($_POST['countryName']))?$_POST['countryName']:'';
$countryName1= explode('(',$countryNames);
$countryName=$countryName1[0];
$code =$code!=''?$code:'91';
$countryName= $countryName!=''?$countryName:'India';
$mobileNumbers= '+'.$code.' - '.$enq_mobile;
  if(strpos($enq_message,'#')!==false || strpos($enq_message,'%')!==false || strpos($enq_message,'@')!==false || strpos($enq_message,'&')!==false || strpos($enq_message,'~')!==false || strpos($enq_message,'https')!==false || strpos($enq_message,'http')!==false || strpos($enq_message,'www')!==false || strpos($enq_message,'?')!==false){
      $res ='<div class="alert alert-danger alert-dismissible  show">URL(s) and special characters are not allowed <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
  } else {
if($enq_name!='' &&  $enq_email!='' && $enq_mobile!='' && $enq_location!='' && $enq_message!='' && $ip!=''){
    
  if (filter_var($enq_email, FILTER_VALIDATE_EMAIL)) {
if(strlen($enq_mobile)==10){

$sql_ens = "insert into tbl_enquiry set en_name='$enq_name', en_email='$enq_email', en_mobile='$enq_mobile', en_country='$enq_location', en_comment='$enq_message', en_zcode='$code', en_country_name='$countryName', en_url='$referer', en_date='$date', en_ip='$ip'";

   $qry = mysqli_query($dbconn,$sql_ens);
        
$name = $enq_name;
$email = $enq_email;
$subject = utf8_encode('Webpulseindia.com '.' - '. $admin_res['subject']);
// $htmlContent = "
// Customer Details:

// Url: $referer

// Your Name: " . $enq_name . "

// Mobile: " . $enq_mobile . "

// Email: " . $enq_email . "

// Location: " . $enq_location . "

// Message: " . $enq_message . "
// ";
$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>Email Id : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $email . '</span></td>
  </tr>

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

  <tr>
  <td>
    <strong>Country : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $countryName . '</span></td>
  </tr>
    <tr>
  <tr>
    <td>
      <strong>Location : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $enq_location . '</span></td>
  </tr>
  <tr>
    <td>
      <strong>Message : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $enq_message . '</span></td>
  </tr>
</tbody>
       
        </table>';
             
// $to =  $admin_res['email'];
// $to2 = $admin_res['cc'];
// $to3 = $admin_res['bcc'];
$to3 = 'tanuja.wpsranchi@gmail.com';


 
		
    // $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
    //         'Reply-To:  '.$name.'<'.$email.'>' . "\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, $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 alert-dismissible  show">Your Enquiry has been sent successfully. Our Team will contact you shortly!<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
     $enq_name='';
            $enq_mobile='';
            $enq_email='';
            $enq_location='';
            $enq_message='';
}
    else{
        $res = '<div class="alert alert-danger alert-dismissible  show">Please Enter 10 Digit Mobile Number. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
    }
    }
    else{
       $res = '<div class="alert alert-danger alert-dismissible  show">Invalid Email Format <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';  
    }
}
        else {
                $res = '<div class="alert alert-danger alert-dismissible  show">Asterisk(*) Marked fields are Mandatory. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
        }
    }
    echo $res;
    ?>
