PHP - 使用 Mailchimp API 订阅群组

标签 php api mailchimp

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

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

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

这是我的代码:

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。之前,我没有注意到我下载的是 Mailchimp API 2.0+,但是对于我上面的代码,我应该使用 API 1.0+ 版本。

关于PHP - 使用 Mailchimp API 订阅群组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36029977/

相关文章:

javascript - 自定义 Stripe 结账按钮无法在移动设备上使用

php - Laravel Entrust,查询用户没有角色的地方

api - 音频数据API节拍检测

html - 为什么 Image 在 table 里面这么小?

coldfusion - Mailchimp API listsubscribe() 未将订阅者添加到我的列表

javascript - php - 临时存储用户选择

php - 如何在时间格式之间进行转换?

c# - GPS定位API?

api - 如何在 api 模式下使用 Rails 5 时创建自定义中间件?

node.js - 无法在 Node.js 中交换访问 token 的代码。 Mailchimp API