<?php
include('include/config.php');
include_once("include/main.inc.php");
date_default_timezone_set('Asia/Kolkata');
$enq_date = date('Y-m-d H:i:s');
$admin_sql=mysqli_query($GLOBALS['dbconn'],
"select * from admin_details");
$admin_res=mysqli_fetch_array($admin_sql);
$referer = $_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];
if(isset($_POST['name'])){
    $name = $_POST['name'];
    $mobile = $_POST['mobile'];
    $email = 'enquiry@webpulseindia.com';
    if($name != '' && $mobile != '' && $ip != '' ){
        if(strlen($mobile) != '10'){
            $resp = [
                'message_response' => 'Mobile Number must have 10 digits!!!',
                'status' => false
            ];
            echo json_encode($resp);
            exit;
        }
        $save_enquiry = "Insert into tbl_enquiry(en_name, en_mobile, en_url, en_ip, en_comment) value('".$name."', '".$mobile."', '".$referer."','".$ip."', 'Request Callback Enquiry')";
        $result = $dbconn->query($save_enquiry);
        $subject = "Callback Request ".utf8_encode('Callback Request Enquiry 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;">' . $mobile . '</span></td>
  </tr>

</tbody>
       
        </table>';
        $to = $admin_res['email'];
        $to2 = $admin_res['cc'];
        $to3 = $admin_res['bcc'];

      
        if($to!='')
         {
         smtp_mailer($to, $email, $name, $subject, $htmlContent);
         }
         if($to2!='')
         {
         smtp_mailer($to2, $email, $name, $subject, $htmlContent);
         }
        if($to3){
         smtp_mailer($to3, $email, $name, $subject, $htmlContent);
        }
    
        $resp = [
            'message_response' => 'Thank you for your enquiry. Our team will contact you soon.',
            'status' => true
        ];
        echo json_encode($resp);
        exit;

    }else {
        $resp = [
            'message_response' => 'All Fields are Mandatory.',
            'status' => false
        ];
        echo json_encode($resp);
        exit;
    }
}
    