繁体   English   中英

PHP - 使用Mailchimp API订阅组

[英]PHP - Subscribe to Group using Mailchimp API

我按照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>

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

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

暂无
暂无

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

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