【问题标题】:PHP - Subscribe to Group using Mailchimp APIPHP - 使用 Mailchimp API 订阅群组
【发布时间】:2016-07-01 23:54:51
【问题描述】:

我按照 Drewm/Mailchimp API 将自定义表单集成到 Mailchimp 中。

我已成功将用户订阅到我的列表。但是当我包含订阅组代码行时,整个功能不起作用,甚至订阅列表也不起作用了。

但是当我删除订阅组时,订阅列表又可以工作了。

这是我的代码:

include 'MailChimp.php';

$MailChimp = new \Drewm\MailChimp('ab4dc1be0f31933f5f8bcdc82231a47d-us4');
$result = $MailChimp->call('lists/subscribe', array(
    'id'                => '0c043be204',
    'email'             => array('email'=>$email),
    'merge_vars'        => array('FNAME'=>$firstname, 'LNAME'=>$lastname),
    //                     'groupings' => array(
    //                         array( 
    //                             'id' => 19361, 
    //                             'groups' => array($_POST['group'])
    //                         ) 
    //                     )
    // ),
    'double_optin'      => false,
    'update_existing'   => true,
    'replace_interests' => false,
    'send_welcome'      => false,
));

print_r($result);

我的 HTML 表单如下所示:

<div class="col-md-6">
    <label>Email Address</label><br>
    <input name="Email" type="email" required="required" id="Email" placeholder="Email">

    <label>First Name</label><br>
    <input name="FirstName" type="text" required="required" id="FirstName" placeholder="First Name">

    <label>Last Name</label><br>
    <input name="LastName" type="text" required="required" id="LastName" placeholder="Last Name">

    <div id="group">
    <label>Areas of Interest</label><br>
    <input name="group[]" type="checkbox" id="Interest1" class="interest"><label>Turf</label><br>
    <input name="group[]" type="checkbox" id="Interest2" class="interest"><label>Landcare</label><br>
    <input name="group[]" type="checkbox" id="Interest3" class="interest"><label>Landscaping</label><br>
    <input name="group[]" type="checkbox" id="Interest4" class="interest"><label>Landscaping Architects</label><br>
    <input name="group[]" type="checkbox" id="Interest5" class="interest"><label>Nurseries</label>
</div>

我不知道我缺少什么或代码有什么问题。希望可以有人帮帮我。谢谢!

【问题讨论】:

  • 您从 API 收到什么错误?
  • 没有错误。它只是没有做它应该做的事情。当我运行上面的代码时,它工作正常。但是当我删除评论时,删除“$lastname”上的“)”然后它就不再起作用了。
  • “不起作用”是什么意思?就像它根本不订阅用户一样?您从 MailChimp 收到的响应的实际正文是什么?
  • 是的,当我包含注释代码时,它不会订阅用户。 Mailchimp 也没有任何回应。

标签: php api mailchimp


【解决方案1】:

两天后我终于弄明白了!!代码结构是正确的,我的错是我使用了错误的 API 版本。之前,我没注意到我下载的是Mailchimp API 2.0+,但是对于我上面的代码,我应该使用API​​ 1.0+版本。

【讨论】:

    猜你喜欢
    • 2013-12-14
    • 2011-12-05
    • 2017-06-11
    • 2018-02-11
    • 2014-07-12
    • 2013-08-27
    • 2013-11-09
    • 2015-08-13
    • 2015-06-02
    相关资源
    最近更新 更多