Last active
August 29, 2015 14:06
-
-
Save jawinn/7926ee12b17bf2c1d4bc to your computer and use it in GitHub Desktop.
Add a Subscribe to MailChimp Newsletter Option on Your Contact Form - PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SUBSCRIBE TO MAILING LIST OPTION - ADD TO MAILCHIMP USING API | |
if ( $_POST['emailUpdates'] == 'Yes' ) | |
{ | |
// Include Mailchimp API class | |
require_once('MCAPI.class.php'); | |
// Your API Key: http://admin.mailchimp.com/account/api/ | |
$api = new MCAPI('YourAPIKeyHere'); | |
// Your List Unique ID: http://admin.mailchimp.com/lists/ (Click "settings") | |
$list_id = "YourListIDHere"; | |
// Variables in your form that match up to variables on your subscriber | |
// list. You might have only a single 'name' field, no fields at all, or more | |
// fields that you want to sync up. | |
$merge_vars = array( | |
'FNAME' => $_POST['firstName'], | |
'LNAME' => $_POST['lastName'] | |
); | |
// SUBSCRIBE TO LIST | |
if ( $api->listSubscribe($list_id, $_POST['email'], $merge_vars) === true ){ | |
$mailchimp_result = 'Success! Check your email to confirm sign up.'; | |
} else { | |
$mailchimp_result = 'Error: ' . $api->errorMessage; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment