/* txt file setting */
define('FL_MAIL', 'emails.txt');
/* File error log */
define('ERROR_LOG', 'error-log.txt');
/* Install headers */
header('Expires: 0');
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
header('Content-Type: application/json; charset=utf-8');
/* AJAX check */
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    extract($_POST);
    try {
        if (isset($subscribe) && validateMail($subscribe)) {
            saveFile($subscribe);
            sendMailChimp($subscribe);
            sendGetResponse($subscribe);
            sendAWeber($subscribe);
            sendCompaingMonitor($subscribe);
            sendiContact($subscribe);
        } else {
            throw new Exception("Email not valid", 1);
        }
    } catch (Exception $e) {
        $code = $e->getCode();
    }
    echo $code ? $code : 0;
} else {
    echo 'Only Ajax request';
}
function validateMail($email)
            sendMailChimp($user_Email, $pix_extra);
        } elseif ($the_type == 'cm') {
            sendCampaign($user_Email, $pix_extra);
        } elseif ($the_type == 'gr') {
            sendGetResponse($user_Email, $pix_extra);
        } elseif ($the_type == 'aw') {
            sendAWeber($user_Email, $pix_extra);
        } else {
            $output = json_encode(array('type' => 'error', 'text' => 'Error: Wrong pix-form-type attribute provided for the form!'));
            die($output);
        }
    } else {
        if ($mail_type == 'ce') {
            pixmail($o_string, $user_Email, $to_Email, $subject);
        } elseif ($mail_type == 'mc') {
            sendMailChimp($user_Email, $pix_extra);
        } elseif ($mail_type == 'cm') {
            sendCampaign($user_Email, $pix_extra);
        } elseif ($mail_type == 'gr') {
            sendGetResponse($user_Email, $pix_extra);
        } elseif ($mail_type == 'aw') {
            sendAWeber($user_Email, $pix_extra);
        } else {
            $output = json_encode(array('type' => 'error', 'text' => 'Error: Wrong mail_type attribute provided in config.php file!'));
            die($output);
        }
    }
}
// End POST
function pixmail($o_string, $user_Email, $to_Email, $subject)
{