<?php 
include_once("include/main.inc.php");
@extract($_POST);
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'];

      $name = !empty($_POST['name'])?$_POST['name']:'';
      $email = !empty($_POST['email'])?$_POST['email']:'';
      $mobileNumber = (!empty($_POST['mobile']))?$_POST['mobile']:'';
      $gender = !empty($_POST['gender'])?$_POST['gender']:'';
      $salary = !empty($_POST['salary'])?$_POST['salary']:'';
      $availability = !empty($_POST['availability'])?$_POST['availability']:'';
      $work = !empty($_POST['work'])?$_POST['work']:'';
      $remote = !empty($_POST['remote'])?$_POST['remote']:'';
   
      // $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.' - '.$mobileNumber;
     
      $image = !empty($_FILES["formFile"]["name"])?$_FILES["formFile"]["name"]:'';
      if($_FILES['formFile']['name']!="") {

  $target_file = "uploaded-files/pdf/".basename($_FILES["formFile"]["name"]);
 move_uploaded_file($_FILES["formFile"]["tmp_name"], $target_file);
}
      if( strpos($name,'#')!==false || strpos($name,'%')!==false || strpos($name,'@')!==false || strpos($name,'&')!==false || strpos($name,'~')!==false || strpos($name,'https')!==false || strpos($name,'http')!==false || strpos($name,'www')!==false || strpos($name,'?')!==false){
          $resp = [
              'message_response' => 'URL(s) and special characters are not allowed',
              'status' => false
          ];
          echo json_encode($resp);
          exit;
      } else {   
          if($name != '' && $email != ''  && $mobileNumber != ''){
             
 
          $sql_ens="insert into tbl_enquiry set en_name='$name', enq_type='3', en_email='$email', en_mobile='$mobileNumber',
          en_doc_name='$image', en_url='$referer', en_date='$enq_date', gender='$gender', salary='$salary', availability='$availability', work='$work', remote='$remote', term='$term', en_ip='$ip'";
          $qry=mysqli_query($GLOBALS['dbconn'],
          $sql_ens);
          $subject = utf8_encode('Career Enquiry From '. site_url);
          // $htmlContent = "
          // Customer Details:
          // Url: ".$referer."
          // Name: ".$name."
          // Email: ".$email."
          // Mobile: ".$mobileNumber."
          // Location:".$location."
          // Message: ".$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;">' . $mobileNumber . '</span></td>
</tr>

<tr>
  <td width="26%">
    <strong>Gender : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $gender . '</span></td>
</tr>
<tr>
  <td width="26%">
    <strong>Salary Range: </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $salary . '</span></td>
</tr>
<tr>
  <td width="26%">
    <strong>Availability : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $availability . '</span></td>
</tr>
<tr>
  <td width="26%">
    <strong>Work : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $work . '</span></td>
</tr>
<tr>
  <td width="26%">
    <strong>Remote : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $remote . '</span></td>
</tr>
<tr>
  <td>
    <strong>Resume : </strong></td>
  <td>
    <span style="margin-top: 15px;"><a href="' . site_url . '/uploaded-files/pdf/'.$image.'">View Resume</a></span></td>
</tr>
</tbody>
      </table>';
          $to = $admin_res['email'];
          $to2 = $admin_res['cc'];
          $to3 = 'webpulseindia@gmail.com';   
          // $to3 = 'developer1.wpsrnc@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' => 'Thank you for your enquiry. Our team will contact you soon.',
              'status' => true
          ];
          echo json_encode($resp);
          exit;
      
//   }
//   else {
//       $resp = [
//           'message_response' => 'Please accept term and condition!',
//           'status' => false
//       ];
//       echo json_encode($resp);
//       exit;
//  }
}
else {
  $resp = [
      'message_response' => 'All the fields are Mandatory!',
      'status' => false
  ];
  echo json_encode($resp);
  exit;
}
      }

?>