我一直在尝试使用Mailchimp API将联系人添加到Mailchimp列表中。我使用JQuery处理表单,并使用PHP脚本与Mailchimp API通信。但我是遵循的例子:https://github.com/drewm/mailchimp-api/blob/master/README.md
HTML:<form name="SubsribeForm1" id="SubsribeForm1">
<input name="email" id="emailAdd" type="text" />
<p class="err"><span id="msg"></span></p>
<button id="SubscribeEmail">Submit</button>
</form>
JS代码:
<script>
$('#reset-modal').click(function() {
$('#msg').html("");
});
$(document).on("click", "#SubscribeEmail", function(e){
e.preventDefault();
var emailAdd = $('input[name="email"]').val();
console.log(emailAdd);
$.ajax({
url: "subscribe.php",
data: $('#SubsribeForm1').serialize(),
dataType: "json",
timeout: 15000,
success: function(response){
switch(response.status){
case 'saved':
$('#msg').html(response.message);
break;
case 'empty':
$('#msg').html(response.message);
break;
default:
$('#msg').html(response.message);
}
},
error: function(response){
$('#msg').html(response.status);
}
});
});
</script>
和subscribe.php:
require("_mc.php");
use 'DrewM'MailChimp'MailChimp;
$MailChimp = new MailChimp('7d446f0db3c6f9e4b5f9b6f35a587fad-us10');
$result = $MailChimp->post('lists/02801ed82a/members', array(
'email_address' => $_POST["email"],
'status' => 'subscribed'
));
if($result){
$status = $result["status"];
if($status == "subscribed"){
echo "Great! We will keep you updated on our progress.";
}
else{
echo "Oops! Something went wrong. Please try again.";
}
}
我一直得到一个500错误,无法识别这里的问题。
Apache错误日志:
[Wed Oct 26 16:09:13.836172 2016] [:error] [pid 11669] [client 185.11.237.250:58101] PHP Fatal error: Uncaught exception 'Exception' with message 'cURL support is required, but can't be found.' in /var/www/html/_mc.php:110'nStack trace:'n#0 /var/www/html/_mc.php(48): DrewM''MailChimp''MailChimp->makeRequest('post', 'lists/02801ed82...', Array, 10)'n#1 /var/www/html/subscribe.php(11): DrewM''MailChimp''MailChimp->post('lists/02801ed82...', Array)'n#2 {main}'n thrown in /var/www/html/_mc.php on line 110, referer: http://meanwise.com/
[Wed Oct 26 16:09:17.195803 2016] [:error] [pid 11667] [client 185.11.237.250:58100] PHP Notice: Undefined index: email in /var/www/html/subscribe.php on line 9, referer: http://meanwise.com/
[Wed Oct 26 16:09:17.195942 2016] [:error] [pid 11667] [client 185.11.237.250:58100] PHP Fatal error: Uncaught exception 'Exception' with message 'cURL support is required, but can't be found.' in /var/www/html/_mc.php:110'nStack trace:'n#0 /var/www/html/_mc.php(48): DrewM''MailChimp''MailChimp->makeRequest('post', 'lists/02801ed82...', Array, 10)'n#1 /var/www/html/subscribe.php(11): DrewM''MailChimp''MailChimp->post('lists/02801ed82...', Array)'n#2 {main}'n thrown in /var/www/html/_mc.php on line 110, referer: http://meanwise.com/
[Wed Oct 26 16:09:31.813947 2016] [:error] [pid 11668] [client 185.11.237.250:58136] PHP Notice: Undefined index: email in /var/www/html/subscribe.php on line 9
[Wed Oct 26 16:09:31.814129 2016] [:error] [pid 11668] [client 185.11.237.250:58136] PHP Fatal error: Uncaught exception 'Exception' with message 'cURL support is required, but can't be found.' in /var/www/html/_mc.php:110'nStack trace:'n#0 /var/www/html/_mc.php(48): DrewM''MailChimp''MailChimp->makeRequest('post', 'lists/02801ed82...', Array, 10)'n#1 /var/www/html/subscribe.php(11): DrewM''MailChimp''MailChimp->post('lists/02801ed82...', Array)'n#2 {main}'n thrown in /var/www/html/_mc.php on line 110
[Wed Oct 26 16:09:36.833363 2016] [:error] [pid 31170] [client 185.11.237.250:58140] PHP Notice: Undefined index: email in /var/www/html/subscribe.php on line 9
[Wed Oct 26 16:09:36.833503 2016] [:error] [pid 31170] [client 185.11.237.250:58140] PHP Fatal error: Uncaught exception 'Exception' with message 'cURL support is required, but can't be found.' in /var/www/html/_mc.php:110'nStack trace:'n#0 /var/www/html/_mc.php(48): DrewM''MailChimp''MailChimp->makeRequest('post', 'lists/02801ed82...', Array, 10)'n#1 /var/www/html/subscribe.php(11): DrewM''MailChimp''MailChimp->post('lists/02801ed82...', Array)'n#2 {main}'n thrown in /var/www/html/_mc.php on line 110
修复curl问题后,我得到以下错误(我不是PHP专业人士):
[Thu Oct 27 11:00:54.503907 2016] [:error] [pid 16992] [client 85.53.86.120:64765] PHP Notice: Undefined index: email in /var/www/html/subscribe.php on line 9, referer: http://meanwise.com/
目前您的服务器不支持curl。用fex下载curl。Ubuntu和Apache服务器:
apt-get install php5-curl
/etc/init.d/apache2 restart
如果您使用类似XAMPP的代码,取消注释行:
;extension=php_curl.dll
在xampp'apache'bin'php.ini
或xampp'php'php.ini
重新启动Apache服务。
在您的$_POST
数组中没有索引email
。用echo $_POST
检查它的内容,也许你在拼写上犯了一些错误。