I have made a onepage website, where you can, amongst other things, subscribe to a newsletter list on Mailchimp. The subscription is made with Ajax, calling a php script, which then uses the MailChimp php api to add the subcriber to a list.
The weird things is, it is working on my localhost xampp environment, but not on the production server? Could it be something related to Curl or alike?
I already checked that Curl is enabled though, so im kinda clueless on this one.
Error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
jQuery:
$.ajax({
url: 'ajax/Newsletter.php',
data: {
email: $("#mce-EMAIL").val()
},
dataType: 'json',
type: 'POST',
success: function (msg) {
hideSpinner();
if (msg == "success") {
$("#mce-EMAIL").val("");
showAlert("Success!", "You have successfully subscribed to our mailing list", "success", "OK");
} else {
showAlert("Oops...", "The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.", "error", "OK");
}
},
error: function (jqXHR) {
hideSpinner();
console.log(jqXHR);
showAlert("Oops...", "Something went wrong. Please try again later!", "error", "OK");
}
});
Newsletter.php:
<?php
require("../includes/MailChimp.php");
require("../includes/Config.php");
$api_key = API_KEY;
$list_id = LIST_ID;
$Mailchimp = new Mailchimp($api_key);
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp);
$subscriber = $Mailchimp_Lists->subscribe($list_id, array('email' => htmlentities($_POST['email'])), null, 'html', false);
sleep(1);
if (!empty($subscriber['leid'])) {
echo json_encode("success");
} else {
echo json_encode("fail");
}