<?php
require_once("MailChimp.class.php");
require_once('variables.php');

$email = $_POST['email'];
$MailChimp = new MailChimp($MailChimpApiKey);
$result = $MailChimp->call('lists/subscribe', array(
                'id'                => $MailChimpListId,
                'email'             => array('email'=>$email),
                'double_optin'      => false,
                'update_existing'   => true,
                'replace_interests' => false,
                'send_welcome'      => false,
            ));

if ($result['status'] === 'error'){
	  //throw new Exception();
		echo json_encode(
			array(
				'status' => 'error',
				'message' => $result['error']
			)
		);    
} else {
		echo json_encode(
			array(
				'status' => 'success',
				'message' => "Got it, you've been added to our email list."
			)
		);
}
?>