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.