<?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($home_message,'#')!==false || strpos($home_message,'%')!==false || strpos($home_message,'@')!==false || strpos($home_message,'&')!==false || strpos($home_message,'~')!==false || strpos($home_message,'https')!==false || strpos($home_message,'http')!==false || strpos($home_message,'www')!==false || strpos($home_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($homeuser_name!='' &&  $homeemail_address!='' && $homephone_no!='' && $home_services!='' && $home_message!=''){
    
  if (filter_var($homeemail_address, FILTER_VALIDATE_EMAIL)) {
if(strlen($homephone_no)==10){

$sql_ens = "insert into tbl_enquiry set en_name='$homeuser_name', en_email='$homeemail_address', en_mobile='$homephone_no', en_product_name='$home_services', en_comment='$home_message', en_url='$referer', en_date='$date', en_ip='$ip'";

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

$subject = utf8_encode($admin_res['subject']);
// $htmlContent = "
// Customer Details:

// Url: $referer

// Your Name: " . $homeuser_name . "

// Mobile: " . $homephone_no . "

// Email: " . $homeemail_address . "

// Services: " . $home_services . "

// Message: " . $home_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;">' . $homeuser_name . '</span></td>
  </tr>

  <tr>
    <td width="26%">
      <strong>Email Id : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $homeemail_address . '</span></td>
  </tr>

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

  <tr>
    <td>
      <strong>Services : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $home_services . '</span></td>
  </tr>
  <tr>
    <td>
      <strong>Message : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $home_message . '</span></td>
  </tr>

  

</tbody>
       
        </table>';          
$to =  $admin_res['email'];
$to2 = $admin_res['cc'];
$to3 = $admin_res['bcc'];
//  $to3 = 'vicky.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, $homeemail_address, $homeuser_name, $subject, $htmlContent);
         }
         if($to2!='')
         {
         smtp_mailer($to2, $homeemail_address, $homeuser_name, $subject, $htmlContent);
         }
   
         smtp_mailer($to3, $homeemail_address, $homeuser_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>';
     $homeuser_name='';
            $homephone_no='';
            $homeemail_address='';
            $home_services='';
            $home_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;
    ?>
