I'm trying to implement a newsletter on my website using mailchimp API. I've tried the various suggestions made here, without success (I'm a complete newbie for that kind of things).
The code below should be working, however there's something that I don't understand when the user says "Here is an example using version 2.0 of Mailchimp API together with mailchimp-api (a minimal php abstraction class for dealing with the Mailchimp API)."
When I download the file there's no file called 'MailChimp.class.php". Just one called MailChimp.php. Do I need to rename it or something to get include('MailChimp.class.php');
work? And what about the other files part of mailchimp-api, can I just ignore them? Thanks
<?php
include('MailChimp.class.php');
$MailChimp = new MailChimp('API_KEY');
$result = $MailChimp->call('lists/subscribe', array(
'id' => 'LIST_ID',
'email' => array( 'email' => $_POST['email'] ),
'merge_vars' => array(
'MERGE2' => $_POST['name'] // MERGE name from list settings
// there MERGE fields must be set if required in list settings
),
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false
));
if( $result === false ) {
// response wasn't even json
}
else if( isset($result->status) && $result->status == 'error' ) {
// Error info: $result->status, $result->code, $result->name, $result->error
}
?>
HTML:
<div id="email">
<span>Enter your email to sign up</span>
<form action="subscribe.php" id="invite" method="POST">
<input type="text" placeholder="your@email.com" name="email" id="address" data-validate="validate(required, email)"/>
<button type="submit">»</button>
</form>
<span id="result"></span>
</div>