2015-10-16 137 views
0

每篇文章:http://codeandfun.blogspot.com/2014/02/mailchimp-api-subscribe-user-email.html,我已經設置了我的意見,並要求mailchimp API。我得到一個500內部服務器錯誤,不知道爲什麼。這裏是 「test.php的」:問題與mailchimp API訂閱用戶

<?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="[email protected]" 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._-][email protected][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 
+0

什麼是錯誤響應的主體,並且您是否聯繫了MailChimp API支持? – TooMuchPete

+0

好吧,我更新了帖子 –

+0

你顯示你的客戶端JS錯誤。什麼是返回的MailChimp錯誤? – TooMuchPete

回答

0

魔鬼是在細節,mailchimp預計該列表的ID不同於所述列表的URL中隱含的ID。您必須導航至列表設置>列表名稱和廣告系列默認值才能獲取正確的ID。問題解決了。