3

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="[email protected]" name="email" id="address" data-validate="validate(required, email)"/>
            <button type="submit">&#187;</button>
        </form>
        <span id="result"></span>
    </div>
3
  • Have you tried renaming it to MailChimp.class.php? Commented May 28, 2014 at 16:24
  • Yes, without success... :-/
    – Greg
    Commented May 28, 2014 at 19:27
  • I suggest you look through some of the question here on SO then. I have found some in the past. Commented May 28, 2014 at 19:29

1 Answer 1

1

I accessed the link you mentioned, https://github.com/drewm/mailchimp-api, and in the description, the author shows a piece of code as example.

$MailChimp = new \Drewm\MailChimp('abc123abc123abc123abc123abc123-us1');

I guess you just need to include the file (don't need to rename it) and then access the library using his namespace "\Drewn".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.