/** * Handles the action when subscribe is being done * * @param Array $data * @param Form $form */ public function subscribe(array $data, Form $form) { $settings = SiteConfig::current_site_config(); $MailChimp = new \Drewm\MailChimp($settings->APIKey); $apiData = array('id' => $settings->MailChimpList()->filter(array('Code' => 'NEWSLETTER'))->First()->ListID, 'email' => array('email' => $data['Email']), 'double_optin' => false, 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => false); $this->extend('updateAPIData', $apiData); $result = $MailChimp->call('lists/subscribe', $apiData); if (Director::is_ajax()) { if (isset($result['status']) && $result['status'] == 'error') { if ($result['code'] == 214) { return json_encode(array('success' => false, 'message' => $data['Email'] . ' is already subscribed')); } else { return json_encode(array('success' => false, 'message' => $result['error'])); } } else { return json_encode(array('success' => true, 'message' => 'Thank you for subscribing to our newsletter')); } } else { if (isset($result['status']) && $result['status'] == 'error') { if ($result['code'] == 214) { $this->sessionMessage($data['Email'] . ' is already subscribed.', 'bad'); } else { $this->sessionMessage($result['error'], 'bad'); } } else { $this->sessionMessage('Thank you for subscribing to our newsletter', 'good'); } Controller::curr()->redirectBack(); } }
/** * Submit the form * * @param $data * @param $form * @return bool|SS_HTTPResponse */ public function Subscribe($data, $form) { /** @var Form $form */ $data = $form->getData(); /** Set the form state */ Session::set('FormInfo.Form_' . $this->name . '.data', $data); $siteConfig = SiteConfig::current_site_config(); /** Check if the API key, and List ID have been set. */ if ($siteConfig->MailChimpAPI && $siteConfig->MailChimpListID) { $mailChimp = new \Drewm\MailChimp($siteConfig->MailChimpAPI); $result = $mailChimp->call('lists/subscribe', array('id' => $siteConfig->MailChimpListID, 'email' => array('email' => $data['Email']))); } else { /** If not, redirect back and display a flash error. */ $this->controller->setFlash('Missing API key, or List ID', 'danger'); return $this->controller->redirectBack(); } /** * If the status of the request returns an error, * display the error */ if (isset($result['status'])) { if ($result['status'] == 'error') { $this->controller->setFlash($result['error'], 'danger'); return $this->controller->redirectBack(); } } /** Clear the form state */ Session::clear('FormInfo.Form_' . $this->name . '.data'); if ($siteConfig->MailChimpSuccessMessage) { $this->controller->setFlash($siteConfig->MailChimpSuccessMessage, 'success'); } else { $this->controller->setFlash('Your subscription has been received, you will be sent a confirmation email shortly.', 'success'); } return $this->controller->redirect($this->controller->data()->Link()); }
public function create_subscription($data = null) { $settings = get_option('fwe_settings'); if (!fwe_theme_option_exists('mailchimp_api_key')) { return new WP_Error('apikey', 'Please enter a MailChimp API key in Theme Options'); } if (!fwe_theme_option_exists('mailchimp_list_id')) { return new WP_Error('nolist', 'Please select a MailChimp list in Theme Options'); } if (!array_key_exists('name', $data) || empty($data['name'])) { return new WP_Error('noname', 'Please enter your name and try again!'); } if (!array_key_exists('email', $data) || empty($data['email']) || !is_email($data['email'])) { return new WP_Error('noemail', 'Please enter a valid email address and try again!'); } $first_name = fwe_get_given_name($data['name']); $last_name = fwe_get_surname($data['name']); $chimp = new \Drewm\MailChimp($settings['mailchimp_api_key']); $result = $chimp->call('lists/subscribe', array('id' => $settings['mailchimp_list_id'], 'email' => array('email' => $data['email']), 'merge_vars' => array('FNAME' => $first_name, 'LNAME' => $last_name))); if (array_key_exists('status', $result) && $result['status'] === 'error') { return new WP_Error('error', $result['error']); } $resp = new WP_JSON_Response(); $result['status'] = 'success'; $result['message'] = $settings['subscribe_success_message']; $resp->set_data($result); return $resp; }
/** * Submit user campaign activity to the UserAPI * * @param array $payload * The contents of the queue entry */ public function consumerQueue($message) { echo '------- mbc-resubscribe-mailchimp MBI_MailchimpResubscribe consumerQueue START' . date('D M j G:i:s T Y') . ' -------', PHP_EOL; $resubscribe = unserialize($message->body); // Submit subscription to Mailchimp $mc = new \Drewm\MailChimp($this->settings['mailchimp_apikey']); // Debugging //$results1 = $mc->call("lists/list", array()); //$results2 = $mc->call("lists/interest-groupings", array('id' => 'f2fab1dfd4')); // DoSomething Members f2fab1dfd4, Old People a27895fe0c $results = $mc->call("lists/subscribe", array('id' => 'a27895fe0c', 'email' => array('email' => $resubscribe['email']), 'merge_vars' => array('groupings' => array(0 => array('id' => $this->settings['mailchimp_grouping_id'])), 'FNAME' => $resubscribe['FNAME'], 'MMERGE10' => isset($resubscribe['birthdate']) ? $resubscribe['birthdate'] : ''), 'double_optin' => FALSE, 'update_existing' => TRUE, 'replace_interests' => FALSE, 'send_welcome' => FALSE)); echo '------- mbc-resubscribe-mailchimp MBI_MailchimpResubscribe consumerQueue - END' . date('D M j G:i:s T Y') . ' -------', PHP_EOL; }
/** * Submit the form * * @param $data * @param $form * @return bool|SS_HTTPResponse */ public function Subscribe($data, $form) { /** ========================================= * @var SiteConfigExtension $siteConfig * @var Form $form ===========================================*/ /** Set the form data to session */ $data = $form->getData(); Session::set('FormInfo.Form_' . $this->name . '.data', $data); $siteConfig = SiteConfig::current_site_config(); /** Get the list id */ $listID = $siteConfig->MailChimpListID; /** Check if the API key, and List ID have been set. */ if ($siteConfig->MailChimpAPI && $listID) { $mailChimp = new \Drewm\MailChimp($siteConfig->MailChimpAPI); // create merge vars $mergeVars = array(); $mergeVars['FNAME'] = $data['Name']; $result = $mailChimp->call('lists/subscribe', array('id' => $listID, 'email' => array('email' => $data['Email']), 'merge_vars' => $mergeVars)); } else { /** If not, redirect back and display an error. */ $this->setMessage('Missing API key, or List ID', 'danger'); if ($this->request->isAjax()) { return json_encode(array('error' => true, 'message' => 'Missing API key, or List ID')); } else { return $this->controller->redirectBack(); } } /** * If the status of the request returns an error, * display the error */ if (isset($result['status'])) { if ($result['status'] == 'error') { $this->setMessage($result['error'], 'danger'); if ($this->request->isAjax()) { return json_encode(array('error' => true, 'message' => $result['error'])); } else { return $this->controller->redirectBack(); } } } /** Clear the form state */ Session::clear('FormInfo.Form_' . $this->name . '.data'); $message = $siteConfig->MailChimpSuccessMessage ?: 'Your subscription has been received, you will be sent a confirmation email shortly.'; $this->setMessage($message, 'success'); if ($this->request->isAjax()) { return json_encode(array('success' => true, 'message' => $message)); } else { return $this->controller->redirect($this->controller->Link('?success=1')); } }
protected function execute(InputInterface $input, OutputInterface $output) { $this->app = $this->getSilexApplication(); $isDryRun = !empty($input->getArgument('dryrun')) ? true : false; $apiKey = $input->getArgument('apikey'); $listId = $input->getArgument('listid'); if (empty($apiKey)) { $output->writeln('Invalid API Key'); return 0; } if (empty($listId)) { $output->writeln('Invalid List Id'); // These should be checked/asserted in the 'addArgument' above return 0; } if ($isDryRun) { $output->writeln('This is a dry run..'); } $date = new \DateTime('today'); $date->setTimezone(new \DateTimeZone('UTC')); $latestJobs = (new \GoRemote\Model\JobModel())->getLatestJobs($this->app, 86400); $latestJobCount = count($latestJobs); // Send 4pm GMT? Before work in SF, close to finishing work in the UK $output->writeln("Found: {$latestJobCount} latest jobs"); if (empty($latestJobCount)) { $output->writeln("Not enough jobs to send an email campaign, quitting.."); return 0; } $MailChimp = new \Drewm\MailChimp($apiKey); //print_r($MailChimp->call('/lists/list')); //exit(1); $createResponse = $MailChimp->call('/campaigns/create', ['type' => 'regular', 'options' => ['list_id' => $listId, 'title' => 'GoRemote.io Daily Digest ' . $date->format('Y-m-d'), 'subject' => 'GoRemote.io Daily Digest ' . $date->format('jS \\of M'), 'from_email' => $this->app['config.dailydigest']['from_email'], 'from_name' => $this->app['config.dailydigest']['from_name'], 'to_name' => $this->app['config.dailydigest']['to_name'], 'template_id' => $this->app['config.dailydigest']['template_id'], 'authenticate' => $this->app['config.dailydigest']['authenticate']], 'content' => ['sections' => ['std_content00' => $this->app['twig']->render('daily-digest-email.html.twig', ['latestJobs' => $latestJobs])]]]); print_r($createResponse); if (!empty($createResponse['id'])) { $campaignId = $createResponse['id']; if ($isDryRun) { $output->writeln("Dry run: Created campaign, but not sending"); } else { $sendResponse = $MailChimp->call('/campaigns/send', ['cid' => $campaignId]); print_r($sendResponse); } } else { print_r($createResponse); $output->writeln('Something went wrong, we couldn\'t create the campaign so we haven\'t attempted to send it'); return 1; } return 0; // exit code of 0 is 'successful' }
public function getLists() { $api_key = $this->get('key'); Loader::library('mailchimp'); $mc = new \Drewm\MailChimp($api_key); $result = $mc->call('lists/list'); $lists = $result['data']; $options = ""; foreach ($lists as $list) { $id = $list['id']; $name = $list['name']; $options .= "<option value={$id}>{$name}</option>"; } echo $options; exit; }
function mailchimpInfo() { require_once 'MailChimp.php'; // same directory as mailchimp-info.php $email_field = trim($_GET['email']); $merge_vars = array('EMAIL' => $email_field); $MailChimp = new \Drewm\MailChimp('ec3c9165886020b954bde777ad52b432-us2'); $result = $MailChimp->call('lists/subscribe', array('id' => '216cf21285', 'email' => array('email' => $email_field), 'merge_vars' => $merge_vars, 'double_optin' => false, 'send_welcome' => true)); $status = $result['status']; if ($status != 'error') { // It worked! echo '<i class="fa fa-check-square"></i> You\'ve been subscribed to our list!'; } else { echo '<i class="fa fa-exclamation-circle"></i> Error - ' . $result['error']; } }
<?php include_once 'MailChimp.php'; $api_key = 'f165592fb351731bba436a58e0a1127e-us8'; $list_id = '633f9eab5f'; $success_message = 'Your email address has been subscribed successfully!'; // Error messages are taken from MailChimp $MailChimp = new \Drewm\MailChimp($api_key); $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $_REQUEST['email']), 'merge_vars' => array('FNAME' => $_REQUEST['fname'], 'LNAME' => $_REQUEST['lname']), 'double_optin' => true, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => true)); if (empty($result['error'])) { print_r('<div class="pi-alert-success fade in"><button type="button" class="pi-close" data-dismiss="alert"><i class="icon-cancel"></i></button><p>' . $success_message . '</p></div>'); } else { print_r('<div class="pi-alert-danger fade in"><button type="button" class="pi-close" data-dismiss="alert"><i class="icon-cancel"></i></button><p>Attention! You have enter an invalid e-mail address, try again.</p></div>'); }
<?php $skip_login = true; require_once 'functions.php'; $list = $db->query("SELECT * FROM mailinglist_options WHERE active = 1 ORDER BY name"); if ($_GET['retry']) { $id = (int) $_GET['id']; $gethash = $_GET['hash']; $info = $db->query("SELECT * FROM people WHERE id = {$id}"); $hash = encrypt($id . $info->email); if ($hash != $gethash) { kill("Hash is invalid"); } require_once 'mailchimp.php'; $MailChimp = new \Drewm\MailChimp(MAILCHIMP_API_KEY); $return = $MailChimp->call('lists/subscribe', array('id' => MAILCHIMP_LIST, 'email' => array('email' => $info->email))); if ($return['status'] == 'error') { $error = "Sorry, there was a problem confirming your registration. Please contact info@openstreets.co.za"; } $print = "Confirmation mail was sent. Please check your e-mail in a few minutes to confirm your account"; } if (trim($_POST['email'])) { $email = mysql_clean(trim($_POST['email'])); $user = $db->query("SELECT * FROM people WHERE email = {$email} LIMIT 1"); if ($user->num_rows) { $id = $user->id; $check = $db->query("SELECT * FROM people_mailinglists WHERE id = {$id}"); } if (!check_mail($_POST['email'])) { $error = "Sorry, you did not provide a valid e-mail address. <a href='javascript:history.back(1)'>Click here to go back.</a>"; } elseif (!is_array($_POST['list'])) {
public static function add_to_mailchimp($values) { require_once 'wp-content/themes/vetri-master/lib/MailChimp/MailChimp.php'; $formatted_phone = substr($values['billing_phone'], 0, 3) . "-" . substr($values['billing_phone'], 3, 3) . "-" . substr($values['billing_phone'], 6); $MailChimp = new \Drewm\MailChimp(ACTIVITY_CENTER_MAILCHIMP_API_KEY); $result = $MailChimp->call('lists/subscribe', array('id' => ACTIVITY_CENTER_MAILCHIMP_LIST_ID, 'email' => array('email' => $values['registrant_1_email']), 'merge_vars' => array('FNAME' => $values['registrant_1_first_name'], 'LNAME' => $values['registrant_1_last_name'], 'MMERGE3' => $formatted_phone), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); if (isset($result['status']) && $result['status'] == 'error') { add_post_meta($values['reservation_id'], '_reservation_notes', 'MailChimp error: ' . $result['error'], true); } }
<?php require_once 'functions.php'; require_once 'mailchimp.php'; $MailChimp = new \Drewm\MailChimp('4ffc6540b34178eda24956a17c0fd057-us4'); $return = $MailChimp->call('lists/segment-add', array('id' => 'b343acd933', 'opts' => array('type' => 'static', 'name' => 'OS Newsletter Details'))); die(var_dump($return)); ?> <!doctype html> <html> <head> <title><?php echo SITENAME; ?> </title> <?php echo $head; ?> </head> <body> <?php require_once 'include.header.php'; ?> <?php require_once 'include.footer.php'; ?> </body> </html>
<?php require_once __DIR__ . "/config.php"; require_once __DIR__ . "/Drewm/MailChimp.php"; $response = array("success" => true, "message" => ""); $listId = isset($_REQUEST['list_id']) ? $_REQUEST['list_id'] : ""; $email = isset($_REQUEST['email']) ? $_REQUEST['email'] : ""; try { if (!$listId) { throw new Exception("List ID is required"); } if (!$email) { throw new Exception("Please enter your email address!"); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new Exception("Please enter a valid email address!"); } $MailChimp = new \Drewm\MailChimp($MAILCHIMP_API_KEY); $result = $MailChimp->call('lists/subscribe', array('id' => $listId, 'email' => array('email' => $email), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); $response["message"] = "Email address {$email} successfuly subscribed!"; $response['result'] = $result; } catch (Exception $e) { $response["success"] = false; $response["message"] = $e->getMessage(); } header('Content-Type: application/json'); echo json_encode($response);
public function press_email($first_name, $last_name, $company, $email, $phone, $title) { $sanitize = function ($data) { //$data = htmlentities(strip_tags(trim($data))); $bad = array("content-type", "bcc:", "to:", "cc:", "href", "\$", "SELECT", "<", ">", ";", "INSERT INTO", "UPDATE", "DELETE"); $data = str_replace($bad, "", $data); $search = array('@<script[^>]*?>.*?</script>@si', '@<[\\/\\!]*?[^<>]*?>@si', '@<style[^>]*?>.*?</style>@siU', '@<![\\s\\S]*?--[ \\t\\n\\r]*>@'); $data = preg_replace($search, '', $data); return $data; }; include_once 'vendor/drewm/mailchimp-api/src/Drewm/MailChimp.php'; $MailChimp = new \Drewm\MailChimp('79cc34986146d7dcdc34345a9f907ca0-us4'); $result = $MailChimp->call('lists/subscribe', array('id' => '04cb5d4836', 'email' => array('email' => $sanitize($email)), 'merge_vars' => array('FNAME' => $sanitize(utf8_decode($first_name)), 'LNAME' => $sanitize(utf8_decode($last_name)), 'COMPANY' => $sanitize($company), 'PHONE' => $sanitize($phone), 'TITLE' => $sanitize(utf8_decode($title))), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); }
} } else { $data["video_id"] = $_POST["video_id"]; $data["meetup_id"] = $_SESSION['user']['meetup_id']; if (!$db->insert("progress", $data)) { $res = array('status' => 'error', 'message' => 'Progress could no be added: ' . $db->getLastError()); } } if (!isset($res)) { $res = array('status' => 'success', 'message' => $data); } echo json_encode($res); }); $app->post('/user/:userid/preferences', 'authenticated', 'same_user', function ($userId) use($app, $db) { global $mailchimp_listid, $mailchimp_apikey; $MailChimp = new \Drewm\MailChimp($mailchimp_apikey); $user = new Member(array("meetup_id" => $_SESSION["user"]["meetup_id"])); $data = array('email' => array("euid" => $user->mailchimp_euid), 'merge_vars' => array('groupings' => array()), 'id' => $mailchimp_listid, 'replace_interests' => true); foreach ($_POST["groups"] as $group) { $grouping = array('id' => $group, "groups" => array()); if (!empty($_POST["{$group}"])) { foreach ($_POST["{$group}"] as $g) { array_push($grouping["groups"], $g); } array_push($data["merge_vars"]["groupings"], $grouping); } } $result = $MailChimp->call('/lists/update-member', $data); if ($result) { $data = array('status' => 'success', 'message' => 'Tus preferencias han sido actualizadas'); } else {
<?php require_once 'MailChimp.php'; ?> <?php //use ZfrMailChimp\Client\MailChimpClient; echo "in requestInvite\n"; $vEmail = $_GET["email"]; $vPhone = $_GET["phone"]; echo "email n phone: {$vEmail} {$vPhone}\n"; $MailChimp = new \Drewm\MailChimp('85852e31e11299161277954ebc513902-us12'); $result = $MailChimp->call('lists/subscribe', array('id' => '30ef3c524b', 'email' => array('email' => $vEmail, 'PHONE' => $vPhone), 'phone' => array('PHONE' => $vPhone))); if (isset($result['email'])) { echo "Please check your email. Your request for an invite has been submitted."; } else { if (isset($result['status']) && $result['status'] === 'error' && $result['name'] !== 'List_AlreadySubscribed') { echo "Error " . $result['name'] . " (" . $result['code'] . "): " . $result['error'] . "."; } else { echo "An unknown error was encountered. Please try again later or contact us."; } } echo "\nout requestInvite";
header('Status: 200 OK'); header('Content-type: application/json'); // Checking if the email writing is good if (filter_var($email, FILTER_VALIDATE_EMAIL)) { /* The part for the storage in a .txt ++++++++++++++++++++++++++++++++++++++++++++++*/ if ($STORE_MODE == "file") { // SUCCESS SENDING if (@file_put_contents($STORE_FILE, strtolower($email) . "\r\n", FILE_APPEND)) { echo json_encode(array("status" => "success")); // ERROR SENDING } else { echo json_encode(array("status" => "error", "type" => "FileAccessError")); } } elseif ($STORE_MODE == "mailchimp") { $MailChimp = new \Drewm\MailChimp($MC_API_KEY); $result = $MailChimp->call('lists/subscribe', array('id' => $MC_LIST_ID, 'email' => array('email' => $email, 'name' => $firstname), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => true)); // SUCCESS SENDING if (isset($result["email"])) { if ($result["email"] == $email) { echo json_encode(array("status" => "success")); } else { echo json_encode(array("status" => "error", "type" => "Looks like something went wrong. Please try again later.")); errorlog("mailchimp", $result["name"]); } // ERROR SENDING } else { /*echo json_encode(array( "status" => "error", "type" => $result["name"] ));*/
$title = ""; if (isset($_GET['title'])) { $title = $_GET['title']; } //titol newsletter $lang = "en"; if (isset($_GET['lang'])) { $lang = $_GET['lang']; } $options = get_option("pimpampum_newsletter_options"); if ($send == "final") { $list_id = $options['ok_list_' . $lang . 'id']; } else { $list_id = $options['test_list_id']; } $MailChimp = new \Drewm\MailChimp($options['api_key']); /* default: veure resultat send='' send=test : a la llista de text send=final : a la llista final */ if ($send != "") { ob_start(); } ?> <style> /* newsletter */ #newsletter-options { position: fixed;
mail($email, $subject, $message, $headers); } } if (isset($_GET['validated'])) { $validated = $_GET['validated']; if (!is_null($validated) and !empty($validated)) { $check = hash('ripemd160', $email . $salt); if ($validated == $check) { $addedSuggFriends = mysql_query("SELECT V.name, V.picture FROM userSuggestedFriend T INNER JOIN user U ON T.userID = U.userID INNER JOIN userFriend V ON T.userFriendID = V.userFriendID WHERE U.userFacebookID = " . $response['id']) or die(mysql_error()); $friends = array(); $friendsURL = array(); while ($addedSuggFriend = mysql_fetch_array($addedSuggFriends)) { array_push($friends, $addedSuggFriend['name']); array_push($friendsURL, $addedSuggFriend['picture']); } $MailChimp = new \Drewm\MailChimp($api_key); $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email), 'merge_vars' => array('FNAME' => $fname, 'LNAME' => $lname, 'FRIEND1' => $friends[0], 'FRIEND1URL' => $friendsURL[0], 'FRIEND2' => $friends[1], 'FRIEND2URL' => $friendsURL[1], 'FRIEND3' => $friends[2], 'FRIEND3URL' => $friendsURL[2], 'FRIEND4' => $friends[3], 'FRIEND4URL' => $friendsURL[3], 'FRIEND5' => $friends[4], 'FRIEND5URL' => $friendsURL[4], 'dayOfWeek' => $day), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); $alert = '<div class="row"> <div class="col-md-2"> </div> <div class="col-md-7"> <div class="alert alert-success alert-dismissible"" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> Your account has been validated! </div> </div> <div class="col-md-3"> </div> </div>';
<?php /* Title: MailChimp Settings Setting: fwe_settings Tab: MailChimp */ // Load MailChimp API wrapper $theme_dir = trailingslashit(dirname(__FILE__)) . '../../../'; require_once $theme_dir . 'includes/vendor/autoload.php'; $fwe_settings = get_option('fwe_settings'); piklist('field', array('type' => 'text', 'field' => 'mailchimp_api_key', 'label' => 'MailChimp API Key', 'description' => 'You can find this by viewing your profile in MailChimp and selecting Extras > API Keys', 'value' => 'cbb2a7e4d7c04540270ae1d494efe0c0-us8')); if (fwe_theme_option_exists('mailchimp_api_key')) { $mc = new \Drewm\MailChimp($fwe_settings['mailchimp_api_key']); $lists = $mc->call('lists/list'); $list_choices = array('' => '-- Select a List --'); foreach ($lists['data'] as $list) { $list_choices[$list['id']] = $list['name']; } piklist('field', array('type' => 'select', 'field' => 'mailchimp_list_id', 'label' => 'Subscriber List', 'choices' => $list_choices)); } piklist('field', array('type' => 'textarea', 'field' => 'subscribe_success_message', 'label' => 'Subscription Success Message', 'description' => 'Displayed to users upon successful subscription to FWE\'s email list. No HTML allowed.', 'value' => 'Thanks for subscribing! Please check your inbox for a confirmation link.', 'attributes' => array('rows' => 4, 'cols' => 40)));
<?php require_once 'MailChimp.php'; $MailChimp = new \Drewm\MailChimp('YOUR API KEY'); if (isset($_POST['email'])) { $check_user = $MailChimp->call('lists/member-info', array('id' => 'YOUR LIST ID', 'emails' => array(array('email' => $_POST['email'])))); //var_dump($check_user["success_count"]); if ($check_user["success_count"] === 1) { http_response_code(200); echo "You have already subscribed to the List"; exit; } $result = $MailChimp->call('lists/subscribe', array('id' => 'YOUR LIST ID', 'email' => array('email' => $_POST['email']), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); if (isset($result["email"]) && isset($result["euid"]) && isset($result["leid"])) { http_response_code(200); echo "Thank You! We've added you to our list."; exit; } else { http_response_code(500); echo "Oops! Something went wrong try again."; exit; } } else { http_response_code(403); echo "There was a problem with your submission, please try again."; }
/** * @return array */ private function setListCall() { $api = parent::getApi(); if ($api != null) { $id = parent::g_list($api['idapi'], $this->getlang); if ($id != null) { $MailChimp = new \Drewm\MailChimp($api['account_api']); return $MailChimp->call('lists/members', array('id' => $id['list_id'])); } } }
<?php require_once '../inc/mailchimpApi.php'; $json = '{ "apikey": "4b194645f469f7a824f6b105fb3b0663-us12", "type": "regular", "options": { "list_id": "057fda416a", "subject": "Täglicher Schnee- & Wetterbericht", "from_email": "example from_email", "from_name": "Wildkogel-Arena", "to_name": "*|FNAME|*", "title": "Newsletter ' . date('Y-m-d') . '", } }'; $arr = json_decode($json, true); $arr = array('apikey' => '4b194645f469f7a824f6b105fb3b0663-us12', 'type' => 'regular', 'options' => array('list_id' => '057fda416a', 'subject' => 'Täglicher Schnee- & Wetterbericht', 'from_email' => '*****@*****.**', 'from_name' => 'Wildkogel-Arena', 'to_name' => '*|FNAME|*', 'title' => 'Täglicher Schneebericht ' . date('Y-m-d') . '', 'template_id' => '24581'), 'content' => array('html' => '')); $api = new \Drewm\MailChimp('4b194645f469f7a824f6b105fb3b0663-us12'); $response = $api->call('/campaigns/create', $arr); $campaignId = $response['id']; $arr = array('apikey' => '4b194645f469f7a824f6b105fb3b0663-us12', 'cid' => $campaignId, 'schedule_time' => date('Y-m-d') . ' ' . '08:30:00'); $response = $api->call('/campaigns/schedule', $arr);
return filter_var($email, FILTER_VALIDATE_EMAIL); } if ($_POST) { $mailchimp_api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXX'; // enter your MailChimp API Key // **** $mailchimp_list_id = 'XXXXXXXXXX'; // enter your MailChimp List ID // **** $subscriber_email = addslashes(trim($_POST['email'])); if (!isEmail($subscriber_email)) { $array = array(); $array['valid'] = 0; $array['message'] = 'Insert a valid email address!'; echo json_encode($array); } else { $array = array(); $merge_vars = array(); require_once 'MailChimp.php'; $MailChimp = new \Drewm\MailChimp($mailchimp_api_key); $result = $MailChimp->call('lists/subscribe', array('id' => $mailchimp_list_id, 'email' => array('email' => $subscriber_email), 'merge_vars' => $merge_vars, 'double_optin' => true, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); if ($result == false) { $array['valid'] = 0; $array['message'] = 'An error occurred! Please try again later.'; } else { $array['valid'] = 1; $array['message'] = 'Thanks for your subscription! We sent you a confirmation email.'; } echo json_encode($array); } }
$db->insert("{$table_name}", $post); $id = $db->insert_id; } header("Location: " . URL . "standard/{$_GET['table']}/saved"); exit; } $list = $db->query("SELECT * FROM {$table_name} WHERE active = 1 ORDER BY id"); if ($id) { $info = $db->query("SELECT * FROM {$table_name} WHERE id = {$id}"); } if ($_GET['saved']) { $print = "Information has been saved"; } if ($_GET['action'] == "mailchimp") { require_once 'mailchimp.php'; $MailChimp = new \Drewm\MailChimp(MAILCHIMP_API_KEY); $return = $MailChimp->call('lists/segment-add', array('id' => MAILCHIMP_LIST, 'opts' => array('type' => 'static', 'name' => $info->name))); if ($return['id']) { $post = array('mailchimp_id' => mysql_clean($return['id'])); $db->update($table_name, $post, "id = {$id}", 1); header("Location: " . URL . "standard/mailinglist/edit/{$id}"); exit; } else { $error = "Segment was not created! <br />Error: " . $return['error']; } } $mainorganizations = $db->query("SELECT * FROM organization_main_types WHERE active = 1 ORDER BY name"); ?> <!doctype html> <html> <head>
/** * Get the groups list. * * @since 1.1.0 * * @param string $list_id ID of the list to get the groups of * * @return mixed Array of groups or error */ public function get_groups($list_id = '') { /* Verify the list ID and try to retrieve it if needed. */ if (empty($list_id)) { return new WP_Error('list_id_missing', __('The list ID is missing.', 'wpmc')); } /* Try to get groups from cache */ $groups = get_transient("wpbo_mc_groups_list_{$list_id}"); if (false !== $groups) { return $groups; } /* Check if the credentials are set. */ if (empty(self::$api_key)) { return new WP_Error('api_credentials_missing', __('The API credentials are missing.', 'wpmc')); } /* Instanciate MailChimp API Wrapper. */ $mc = new \Drewm\MailChimp(self::$api_key); /* Get the lists. */ $groups = $mc->call('lists/interest-groupings', array('id' => $list_id)); /* An error occurred during the request, thus no groups. */ if (isset($groups['status']) && 'error' === $groups['status'] && isset($groups['error'])) { return new WP_Error('api_credentials_missing', $groups['error']); } else { /* Set a transient to reduce load time */ $lifetime = apply_filters('wpbo_mc_list_groups_cache_lifetime', 24 * 60 * 60); set_transient("wpbo_mc_groups_list_{$list_id}", $groups, $lifetime); /* Return the groups */ return $groups; } }
<?php /* Name: Newsletter Subscribe Written by: Okler Themes - (http://www.okler.net) Version: 4.4.0 */ require_once 'mailchimp/mailchimp.php'; // Step 1 - Set the apiKey - How get your Mailchimp API KEY - http://kb.mailchimp.com/article/where-can-i-find-my-api-key $apiKey = '11111111111111111111111111111111-us4'; // Step 2 - Set the listId - How to get your Mailchimp LIST ID - http://kb.mailchimp.com/article/how-can-i-find-my-list-id $listId = '1111111111'; $MailChimp = new \Drewm\MailChimp($apiKey); $result = $MailChimp->call('lists/subscribe', array('id' => $listId, 'email' => array('email' => $_POST['email']), 'merge_vars' => array('FNAME' => '', 'LNAME' => ''), 'double_optin' => false, 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => false)); if (in_array('error', $result)) { $arrResult = array('response' => 'error', 'message' => $result['error']); } else { $arrResult = array('response' => 'success'); } echo json_encode($arrResult);
<?php require_once 'functions.php'; if ($_GET['delete']) { $delete = (int) $_GET['delete']; $info = $db->query("SELECT * FROM segments WHERE id = {$delete}"); require_once 'mailchimp.php'; $MailChimp = new \Drewm\MailChimp(MAILCHIMP_API_KEY); $print .= "Segment was successfully deleted from the database<br />"; if ($info->mailchimp_id) { $return = $MailChimp->call('lists/segment-del', array('id' => MAILCHIMP_LIST, 'seg_id' => $info->mailchimp_id)); if ($return['complete']) { $print .= "<br />Mailchimp segment was also removed"; } else { $error .= "Mailchimp segment was <strong>NOT</strong> removed. Error message: <br />" . $return['error']; } } else { $print .= "No Mailchimp segment was found and therefore not deleted<br />"; } $db->query("DELETE FROM segments WHERE id = {$delete} LIMIT 1"); } $list = $db->query("SELECT * FROM segments ORDER BY date"); ?> <!doctype html> <html> <head> <title><?php echo SITENAME; ?> </title> <?php
/** * Inscription sur mailchimp * @param $mail * @param $fstname * @param $lstname * @param bool $notify */ public function subscribe($mail, $fstname, $lstname, $notify = true) { if (self::install_table() == true) { $api = parent::getApi(); if ($api != null) { $iso = frontend_model_template::current_Language(); $list = parent::getCode($api['idapi'], $iso); if ($list != null) { $code = $list['list_id']; $MailChimp = new \Drewm\MailChimp($api['account_api']); $result = $MailChimp->call('lists/subscribe', array('id' => $code, 'email' => array('email' => $mail), 'merge_vars' => array('FNAME' => $fstname, 'LNAME' => $lstname), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); if ($notify) { $this->getNotify('add'); } } else { $this->getNotify('error'); } } else { $this->getNotify('error'); } } }
public function getPreferences() { global $mailchimp_apikey, $mailchimp_listid; $MailChimp = new \Drewm\MailChimp($mailchimp_apikey); $result = $MailChimp->call('/lists/member-info', array('emails' => array(array("euid" => $this->mailchimp_euid)), 'id' => $mailchimp_listid)); $interests = array(); $groupings = $result["data"][0]["merges"]["GROUPINGS"]; foreach ($groupings as $grouping) { foreach ($grouping["groups"] as $group) { if (intval($group["interested"]) === 1) { $interests[$group["name"]] = true; } } } // Get list preferences $groupings = $MailChimp->call('lists/interest-groupings', array('id' => $mailchimp_listid)); for ($i = 0; $i < sizeof($groupings); $i++) { $groupings[$i]["count"] = sizeof($groupings[$i]["groups"]) - 1; } return array("interests" => $interests, "groupings" => $groupings); }