<?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'];



        $email = !empty($_POST['email'])?$_POST['email']:'';
        $news_sql=mysqli_query($GLOBALS['dbconn'], "select * from newsletter_member where email='$email'");

        if(mysqli_num_rows($news_sql)==0){
            $sql_ens="insert into newsletter_member set email='$email', join_date='$enq_date', ip='$ip'";
            $qry=mysqli_query($GLOBALS['dbconn'],
            $sql_ens);
            $subject = utf8_encode('Newsletter Subscription from - '. site_url);
//             $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>Email : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $email . '</span></td>
  </tr>

</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' => 'Thank you for your Subscriptions.',
                'status' => true
            ];
            echo json_encode($resp);
            exit;
        }	
  
   
else {
    $resp = [
        'message_response' => 'You are already subscriber of our newsletter',
        'status' => false
    ];
    echo json_encode($resp);
    exit;


}

?>