简体   繁体   English

PHP - 使用Mailchimp API订阅组

[英]PHP - Subscribe to Group using Mailchimp API

I followed Drewm/Mailchimp API to integrate may custom form into Mailchimp. 我按照Drewm / Mailchimp API将自定义表单集成到Mailchimp中。

I successfully subscribed the users to my list. 我成功地将用户订阅了我的列表。 But when I include the Subscribe to Group line of codes, the whole function is not working, even the Subscribe to List is not working anymore. 但是当我包含订阅组代码行时,整个功能都无法正常工作,即使订阅列表也不再有效。

But when I remove the Subscribe to Group, the Subscribe to List is working again. 但是,当我删除订阅组时,订阅列表再次正常工作。

Here is my code: 这是我的代码:

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);

My HTML form looks like this: 我的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>

I don't know what I am missing or what is wrong with the code. 我不知道我错过了什么或代码有什么问题。 Hope someone can help me. 希望可以有人帮帮我。 Thank you! 谢谢!

After 2 days I finally figured it out!! 2天后我终于明白了! The code construct is correct, my fault is that I am using a wrong version of the API. 代码构造是正确的,我的错是我使用的是错误版本的API。 Before, I didn't noticed that what I downloaded is the Mailchimp API 2.0+, but for my code above, I should be using the API 1.0+ version. 以前,我没有注意到我下载的是Mailchimp API 2.0+,但对于我上面的代码,我应该使用API​​ 1.0+版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM