index.php代码:
<form role="form" action="form.php" method="post">
<input type="email" id="emailSub" placeholder="Enter your Email Adress" size="30">
<button type="button" id="submit" class="btn">
</form>
form.php代码:
<?php
include_once 'MailChimp.php';
$alertclass = 'alert-warning';
$msg = '';
$email = '';
if (isset($POST['submit'])) {
if (empty($_POST['emailSub'])) {
$msg = 'Please enter a email address.';
} else {
$email = filter_var($_POST['emailSub'], FILTER_SANITIZE_EMAIL);
$mc = new MailChimp('MY-API-KEY');
$result = $mc->call('lists/subscribe', array(
'id' => 'MY-LIST-ID',
'email' => array('email'=>$email),
'double_optin' => true,
'update_existing' => false,
'replace_interests' => false,
'send_welcome' => false
)
);
if (!empty($result['euid'])) {
$msg = 'Thanks, please check your mailbox and confirm the subscription.';
$alertclass = 'alert-success';
} else {
if (isset($result['status'])) {
switch ($result['code']) {
case 214:
$msg = 'You\'re already a member of this list.';
break;
default:
$msg = 'An unknown error occurred.';
$alertclass = 'alert-error';
break;
}
}
}
echo $msg;
}
}
?>
我将它上传到支持5.4 PHP版本的服务器,因此它应该可以工作,但它不会。什么也没发生,没有添加订阅我的mailchimp列表,甚至没有订阅消息。而且我不知道为什么。有什么想法吗?