<?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['pdate']))
    {
        $pname = !empty($_POST['name'])?$_POST['name']:'';
        $pemail = !empty($_POST['email'])?$_POST['email']:'';
        $pmobile = !empty($_POST['mobile'])?$_POST['mobile']:'';
        $pdate = !empty($_POST['pdate'])?$_POST['pdate']:'';
        $package = !empty($_POST['package'])?$_POST['package']:'';
        $ptime = !empty($_POST['ptime'])?$_POST['ptime']:'';
       
            $sql_ens="insert into tbl_enquiry set en_name='$pname', en_email='$pemail', en_mobile='$pmobile', booking_date='$pdate', booking_time='$ptime',package='$package', en_url='$referer',en_comment='Appointment Form', en_date='$enq_date', en_ip='$ip'";
            $qry=mysqli_query($GLOBALS['dbconn'],
            $sql_ens);
$package_sql12 = mysqli_query($GLOBALS['dbconn'],"Select name,amount,id,payment_link from package_tbl where id='$package'");
$package_res12=mysqli_fetch_assoc($package_sql12);
$packagess=ucwords($package_res12['name']).'( ₹ '.$package_res12['amount'].'/- )';
$payment_link=$package_res12['payment_link'];

            $subject = utf8_encode('Webpulseindia.com '.' - '. $admin_res['subject']);
//             $htmlContent = "
//             Customer Details:
//   Url: ".$referer."
//   Mobile: ".$mobileNumber."
//  ";
             $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;">' . $pname . '</span></td>
 </tr>
 <tr>
  <td width="26%">
    <strong>Mobile : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $pmobile . '</span></td>
</tr>
<tr>
 <td width="26%">
   <strong>Email : </strong></td>
 <td>
   <span style="margin-top: 15px;">' . $pemail . '</span></td>
</tr>
   <tr>
    <td width="26%">
      <strong>Appointment Date : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $pdate . '</span></td>
  </tr>
 <tr>
    <td width="26%">
      <strong>Appointment Time : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $ptime . '</span></td>
  </tr>

  <tr>
    <td width="26%">
      <strong>Package : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $packagess . '</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.'<'.$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);
            $resp = [
                'message_response' => $payment_link,
                'status' => true
            ];
            echo json_encode($resp);
            exit;



        }	
  
   
else {
    
    $resp = [
        'message_response' => 'All the fields are Mandatory!',
        'status' => false

    ];

    echo json_encode($resp);
    exit;
}

?>