我遵循drewm/mailchimp api将may自定义表单集成到mailchimp中。
我成功地将用户订阅到我的列表。但当我包含subscribe to group代码行时,整个函数都不工作,甚至subscribe to list也不再工作。
但是当我删除subscribe to组时,subscribe to列表将再次工作。
这是我的代码:

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 - PHP-使用Mailchimp API订阅组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36029977/

10-14 12:10
查看更多