MailChimp API integration

Hi all,

Having an issue in developing a way to directly add users to a MailChimp list.

Using the following:

adduser.php which is placed in the theme folder

    // include the mailchimp php api files that you downloaded
    $api_key = "api key"; //replace with your API key
    $list_id = "listid"; //replace with the list id you're adding the email to
    // set up our mailchimp object, and list object
    $Mailchimp = new Mailchimp( $api_key );
    $Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
    $email = [email protected]'; //replace with a test email
    try {
        $subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => $email ) ); //pass the list id and email to mailchimp
    } catch (Exception $e) {
        //You'll need to write your own code to handle exceptions
    // check that we've succeded

Then using a popup form like this:

defined('C5_EXECUTE') or die("Access Denied.");
<form  role="form" method="post" id="subscribe">
    <input type="email"  id="email" name="email" placeholder="[email protected]" value="">
    <button type="submit">SUBSCRIBE</button>
$(document).ready(function() {
    $('#subscribe').submit(function() {
        if (!valid_email_address($("#email").val()))
            $(".message").html('The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.');

However, get a server 500 error when you try and submit the form. I have looked and played around with the permissions for adduser.php to no avail.

Any pointers much appreciated.

View Replies:
JohntheFish replied on at Permalink Reply
A package to handle mailchimp should soon be available, currently under review in the PRB.