MailChimp API integration

Permalink
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

<?php
    // include the mailchimp php api files that you downloaded
    include('Mailchimp.php');
    $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 = 'my@emailaddress.co.uk'; //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:

<?php
defined('C5_EXECUTE') or die("Access Denied.");
 ?>
<form  role="form" method="post" id="subscribe">
    <input type="email"  id="email" name="email" placeholder="you@yourself.com" value="">
    <button type="submit">SUBSCRIBE</button>
</form>
<script>
$(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.');
        }
        else


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.

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