$api_key = "70537ba9706f593a5dc19cae64426914-us12"; // YOUR-API-KEY-HERE $list_id = "9ae6e05048"; // YOUR-LIST-ID-HERE // Check $recipient if ($recipient === '' || $list_id === '') { returnAndExitAjaxResponse(constructAjaxResponseArray(FALSE, 'APIDATA_IS_NOT_SET', array('error_message' => 'API KEY / LIST ID is not set. Please configure the script.'))); } // Include PHP wrapper include_once 'Mailchimp.php'; $MailChimp = new MailChimp($api_key); try { $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $_POST['email']), 'merge_vars' => array('FNAME' => $_POST['fname']), 'double_optin' => false, 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => true)); returnAndExitAjaxResponse(constructAjaxResponseArray(TRUE)); } catch (Exception $_e) { returnAndExitAjaxResponse(constructAjaxResponseArray(FALSE, 'ERROR_AT_MAILCHIMP', array('error_message' => $_e->getMessage()))); } /* Construct ajax response array Input: Result (bool), Message (optional), Data to be sent back in array */ function constructAjaxResponseArray($_response, $_message = '', $_json = null) { $_responseArray = array(); $_response = $_response === TRUE ? TRUE : FALSE; $_responseArray['response'] = $_response; if (isset($_message)) { $_responseArray['message'] = $_message; } if (isset($_json)) { $_responseArray['json'] = $_json;
$email_content .= "Last Name: {$lname}\n"; $email_content .= "Website: {$website}\n"; $email_content .= "Email: {$email}\n\n"; $email_content .= "Message:\n{$message}\n\n\n"; $email_content .= "CLIENT IP:\n" . get_client_ip() . "\n"; $email_content .= "HOST IP:\n" . $_SERVER['SERVER_ADDR'] . "\n"; // Check if sent try { $sendmailResult = mail($recipient, $subject, $email_content, $headers); if ($sendmailResult === TRUE) { returnAndExitAjaxResponse(constructAjaxResponseArray(TRUE)); } else { returnAndExitAjaxResponse(constructAjaxResponseArray(FALSE, 'ERROR_AT_PHPMAIL', array('error_information' => error_get_last()))); } } catch (Exception $_e) { returnAndExitAjaxResponse(constructAjaxResponseArray(TRUE, 'ERROR_AT_PHPMAIL', array('error_message' => $_e->getMessage()))); } /* Construct ajax response array Input: Result (bool), Message (optional), Data to be sent back in array */ function constructAjaxResponseArray($_response, $_message = '', $_json = null) { $_responseArray = array(); $_response = $_response === TRUE ? TRUE : FALSE; $_responseArray['response'] = $_response; if (isset($_message)) { $_responseArray['message'] = $_message; } if (isset($_json)) { $_responseArray['json'] = $_json;