Problem Syncing Newsletter Submit Form- Mailchimp

Hello,

I am trying to set up a newsletter sign up form which collects only a user’s email address and submits it be stored with Mailchimp.

I am using a modified version of the example at Sitepoint, but I can not get it to work for some reason. Can someone please help me troubleshoot this?

Form:


<head>
<script type="text/javascript" src="js/prototype.js"></script> 
<script type="text/javascript" src="js/mailingList.js"></script>
</head>


<form id="signup" action="<?=$_SERVER['PHP_SELF']; ?>" method="get">
<table id="sign-up-table">
<tbody>
<tr>
<td id="sign-up-email" style="vertical-align: middle;"><center> <label for="email">Join our Mailing List to Stay Current on the Latest Healthcare News:<span id="response">
					<? require_once('inc/store-address.php'); if($_GET['submit']){ echo storeAddress(); } ?>
				  </span>
			  </label></center></td>
<td><input class="rounded-corners" id="email-input" type="text" maxlength="80" name="email" size="23" value="Enter Email..." /></td>
<td>
<input type="submit" id="new-button" value="Sign Up" name="sumbit" /></td>
</tr>
</tbody>
</table>
</form>

PHP files:


<?php


function storeAddress(){
	
	// Validation
	if(!$_GET['email']){ return "No email address provided"; } 

	if(!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*$/i", $_GET['email'])) {
		return "Email address is invalid"; 
	}

	require_once('MCAPI.class.php');
	// grab an API Key from http://admin.mailchimp.com/account/api/
	$api = new MCAPI('ea829e951391385d5ff9ce258a4a017c-us7');
	
	// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
	// Click the "settings" link for the list - the Unique Id is at the bottom of that page. 
	$list_id = "b10826d985";

	if($api->listSubscribe($list_id, $_GET['email'], '') === true) {
		// It worked!	
		return 'Success! Check your email to confirm sign up.';
	}else{
		// An error ocurred, return error message	
		return 'Error: ' . $api->errorMessage;
	}
	
}

// If being called via ajax, autorun the function
if($_GET['ajax']){ echo storeAddress(); }
?>


There was another php file which can be found at http://truckermarketplace.com/inc/MCAPI.class.php

Thanks in Advance.

Off Topic:

Is there a reason why you aren’t using the form code that MailChimp provides? Those forms are so simple that I prefer to use those.

Can I design a custom HTML/CSS form to use? This is going on a landing page, so the styling is very important.

I just looked into it, and I think that is going to work. Thanks a lot Ralph!

Absolutely. They just give you the basic form with the name attributes etc. that will work with their system. The styling is 100% up to you. :slight_smile:

Admittedly, I’ve not had much to do with MailChimp, using CampaignMonitor instead, but I think they are much alike in this regard.