I followed Drewm/Mailchimp API to integrate may custom form into 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:
<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!