<?php
include_once("include/main.inc.php");
date_default_timezone_set('Asia/Kolkata');
$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);
if(isset($_POST['email'])){
    if($_POST['email']){
        $email = $_POST['email'];
        $fromemail = 'enquiry@webpulseindia.com';
        $name = 'Fiyu Jewels';
        $check_email = $dbconn->query("select email from newsletter_member where email = '$email'");
        if($check_email->num_rows > 0){
            $resp = [
                'message_response' => 'This Email is already exists',
                'status' => false
            ];
            echo json_encode($resp);
            exit;
        }else{
            $save_enquiry = "Insert into newsletter_member(email, join_date, status) value('".$email."', '".$date."', 'Active')";
            $result = $dbconn->query($save_enquiry);
    
            $subject = "Subscription on ".utf8_encode($admin_res['companyName']);
            $htmlContent = 'You have Successfully Subscribed on Fiyu Jewels';
            if($email!='')
            {
                smtp_mailer($email, $fromemail, $name, $subject, $htmlContent);
                $resp = [
                    'message_response' => 'Your Subscription is Successful',
                    'status' => true
                ];
                echo json_encode($resp);
                exit;
            }
            
        }
    }else{
        $resp = [
            'message_response' => 'Email id is Required',
            'status' => false
        ];
        echo json_encode($resp);
        exit;
    }
}