function mc_nl_mail() { if (isset($_POST['nl_mail'])) { $email_address = $_POST['nl_mail']; include_once "lib/MailChimp.php"; $mc_api = get_option('sssoon_mailing_options'); $mc_api_key = $mc_api['mailchimp_api']; $mc_list = $mc_api['mclist']; $MailChimp = new MailChimp($mc_api_key); $MailChimp->post('lists/' . $mc_list . '/members', array('email_address' => $email_address, 'status' => 'subscribed')); } }
// 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 = "your-list-id-here"; //Making API call, no change needed here if (!empty($_GET['ajax'])) { // Validation if (empty($_GET['email'])) { echo "No email address provided"; } if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\$/i", $_GET['email'])) { echo "Email address is invalid"; } require_once 'assets/inc/mailchimp/MailChimp.php'; $api = new MailChimp($api_key); $merge_fields = array('FNAME' => !empty($_GET['fname']) ? $_GET['fname'] : '', 'LNAME' => !empty($_GET['lname']) ? $_GET['lname'] : ''); $result = $api->post("lists/{$list_id}/members", array('email_address' => $_GET['email'], 'status' => 'subscribed', 'merge_fields' => $merge_fields), 100); if (!empty($result['status']) && $result['status'] === 'subscribed') { echo 'Success! Check your email to confirm sign up.'; } else { $message = array(); if (!empty($result['title'])) { $message[] = $result['title']; } if (!empty($result['detail'])) { $message[] = $result['detail']; } echo 'Error: ' . implode(' - ', $message); } // After Mailchimp API call executed successfully you can send more emails // to yourself or users. Just uncomment and edit the code below /*
$fs_event = $fs->Api("/events/{$event_json->id}.json"); switch ($fs_event->type) { case 'install.installed': $user = $fs_event->objects->user; $email = $user->email; $first = $user->first; $last = $user->last; /** * MailChimp SDK for API v3 can be downloaded from here: * https://github.com/drewm/mailchimp-api */ require_once '/path/to/mailchimp-api/api-v3/MailChimp.php'; // Subscribe to mailchimp list. $blog_subscribers_list = 'LIST_ID'; $mc = new MailChimp('API_KEY'); $result = $mc->post("lists/{$blog_subscribers_list}/members", array('email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array('FNAME' => $first, 'LNAME' => $last))); break; case 'install.uninstalled': $user = $fs_event->objects->user; $email = $user->email; $first = $user->first; $last = $user->last; $fs_uninstall = $fs->Api("/installs/{$fs_event->objects->install->id}/uninstall.json"); // Send email with your favorite service (we use SendGrid). define('FS__UNINSTALL_REASON_NO_LONGER_NEEDED', 1); define('FS__UNINSTALL_REASON_FOUND_BETTER_PLUGIN', 2); define('FS__UNINSTALL_REASON_USED_FOR_SHORT_PERIOD', 3); define('FS__UNINSTALL_REASON_BROKE_WEBSITE', 4); define('FS__UNINSTALL_REASON_STOPPED_WORKING', 5); define('FS__UNINSTALL_REASON_CANT_CONTINUE_PAYING', 6); define('FS__UNINSTALL_REASON_OTHER', 7);