<?php
require_once('../config.php');
//Connection
require_once("../../db.php");
//Currency
include('currency.php');
if (!empty($_POST)) {
    
    //form validation vars
    $formok = true;
    $errors = array();
    
    //sumbission data
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date      = date('m-d-Y');
    $time      = date('H:i:s');
    
    //form data
    $email     = mysqli_escape_string($conn, $_POST['newsletter']);
    $page_name = mysqli_escape_string($conn, $_POST['page_name']);
    
    //validate form data
    
    //validate email address is not empty
    if (empty($email)) {
        $formok = false;
        //$errors[] = "You have not entered an email";
        //if this is not an ajax request
        
        header('location: ' . SITE . '' . $page_name . '?message=error1&#mail&baseC='.$newcurrency);
        //validate email address is valid
    } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $formok = false;
        //$errors[] = "You have not entered a valid email";
        
        header('location: ' . SITE . '' . $page_name . '?message=error2&#mail&baseC='.$newcurrency);
    }
    
    
    //send email if all is ok
    if ($formok) {
		
        mysqli_query($conn, "INSERT INTO newsletter (news_email, news_ip, date, time) VALUES('$email', '$ipaddress', '$date', '$time')");
        
        header('location: ' . SITE . '' . $page_name . '?message=ok&#mail&baseC='.$newcurrency);
        
    }
    
}
?>