mailchimp API订阅用户的问题

时间:2015-10-16 22:34:19

标签: php mailchimp

根据这篇文章:http://codeandfun.blogspot.com/2014/02/mailchimp-api-subscribe-user-email.html,我设置了我的观点并需要mailchimp API。我收到500内部服务器错误不明白为什么。这是“test.php”:

<?php 
$api_key = "#####";
$list_id = "252557";
require('vendor/mailchimp/src/Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']) ) );
if ( ! empty( $subscriber['leid'] ) ) {
    echo "success";
}
else
{
   echo "fail";
}

?>

这是标记:

<div class="message"></div>

<form action="test.php" role="form" method="post" id="subscribe">

<input type="email"  id="email" name="email" placeholder="you@yourself.com" value="">
<button type="submit">SUBSCRIBE</button>

</form>

这是我的JS:

<script src="scripts/jquery.js"></script>
<script>
$(document).ready(function() {
$('#subscribe').submit(function() {
    if (!valid_email_address($("#email").val()))
    {
        $(".message").html('The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.');
    }
    else
    {

        $(".message").html("<span style='color:green;'>Adding your email address...</span>");
        $.ajax({
            url: 'test.php', 
            data: $('#subscribe').serialize(),
            type: 'POST',
            success: function(msg) {
                if(msg=="success")
                {
                    $("#email").val("");
                    $(".message").html('<span style="color:green;">You have successfully subscribed to our mailing list.</span>');

                }
                else
                {
                  $(".message").html('The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.');  
                }
            }
        });
    }

    return false;
  });
 });
 function valid_email_address(email)
 {
    var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
    return pattern.test(email);
  }
  </script>

以下是来自控制台的完整错误消息:

POST http://127.0.0.1:9000/test.php 500 (Internal Server
Error)jQuery.ajaxTransport.options.send @ jquery.js:9664jQuery.extend.ajax @
jquery.js:9215(anonymous function) @ test-form.php:22jQuery.event.dispatch @  
jquery.js:4670jQuery.event.add.elemData.handle @ jquery.js:4338

1 个答案:

答案 0 :(得分:0)

魔鬼在细节中,mailchimp期望列表的ID不同于所述列表的url中隐含的ID。您必须导航到列表设置&gt;列表名称和广告系列默认为获取正确的ID。问题已解决。