/** * Method to get the field options. * * @return array The field option objects. * @since 1.6 */ protected function getOptions() { // Initialize variables. $options = array(); $app = JFactory::getApplication(); require_once JPATH_SITE . '/components/com_jms/helpers/MCAPI.class.php'; require_once JPATH_SITE . '/components/com_jms/helpers/MCauth.php'; $MCauth = new MCauth(); // Get the component config/params object. $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $api_key = $params->get($paramsPrefix . 'MCapi'); if ($MCauth->MCauth()) { $api = new MCAPI($api_key); $retval = $api->lists(); if (is_array($retval['data'])) { foreach ($retval['data'] as $list) { $options[] = JHTML::_('select.option', $list['id'], JText::_($list['name'])); } } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
public function addAction() { $api = new MCAPI($this->_apiKey); $email = $this->getRequest()->getParam('email'); $retval = $api->lists(); if ($api->errorCode) { Mage::getSingleton('core/session')->addError($this->__('Error: %s', $api->errorMessage)); } else { /*foreach($retval['data'] as $val) { if ($val['name'] === "Prospects") { $prospectListId = $val['id']; } elseif ($val['name'] === "Fashion Eyewear Customers") { $customerListId = $val['id']; } }*/ $customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('email', $email)->getData(); $customerId = $customers[0]['entity_id']; $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter('customer_id', $customerId)->getData(); if (!empty($orders)) { //add to Customer List $listId = $this->customerListId; } else { //add to Prospect list $listId = $this->prospectListId; } $merge_vars = array('FNAME' => $this->getRequest()->getParam('firstname')); if ($api->listSubscribe($listId, $email, $merge_vars) === true) { Mage::getSingleton('core/session')->addSuccess($this->__('Success! Check your email to confirm sign up.')); } else { Mage::getSingleton('core/session')->addError($this->__('Error: %s', $api->errorMessage)); } } $this->_redirectReferer(); }
public function onSignup() { $settings = Settings::instance(); if (!$settings->api_key) { throw new ApplicationException('MailChimp API key is not configured.'); } /* * Validate input */ $data = post(); $rules = ['email' => 'required|email|min:2|max:64']; $validation = Validator::make($data, $rules); if ($validation->fails()) { throw new ValidationException($validation); } /* * Sign up to Mailchimp via the API */ require_once plugins_path() . '/rainlab/mailchimp/vendor/MCAPI.class.php'; $api = new \MCAPI($settings->api_key); $this->page['error'] = null; $mergeVars = ''; if (isset($data['merge']) && is_array($data['merge']) && count($data['merge'])) { $mergeVars = $data['merge']; } if ($api->listSubscribe($this->property('list'), post('email'), $mergeVars) !== true) { $this->page['error'] = $api->errorMessage; } }
function mc_remove_email($email_address) { require_once DIR_WS_CLASSES . 'MCAPI.class.php'; $api = new MCAPI(MAILCHIMP_API); $email = $newsletter['customers_email_address']; $retval = $api->listUnsubscribe(MAILCHIMP_ID, $email, MAILCHIMP_DELETE, MAILCHIMP_SEND_GOODBYE, MAILCHIMP_SEND_NOTIFY); }
public function mc_subscribe() { $email = $this->input->get('email'); if (!$email) { $data['response_type'] = 'error'; $data['response'] = "No email address provided"; } if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\$/i", $email)) { $data['response_type'] = 'error'; $data['response'] = "Email address is invalid."; } else { require_once 'includes/MCAPI.class.php'; $api = new MCAPI('c008756fe177a689e69abf3c5e44a59f-us1'); // 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 = "4249f1e3e5"; if ($api->listSubscribe($list_id, $email, '') === true) { // Success $data['response_type'] = 'success'; $data['response'] = 'Success! Check your email to confirm sign up.'; $data['goal_location'] = 'Home'; //Where did they register? Answer = home page // Set cookie for 7 days (to not load reg panel for 7 days) $c = array('name' => 'close_mc_subscribe', 'value' => 'true', 'expire' => '604800'); $this->input->set_cookie($c); } else { $data['response_type'] = 'error'; $data['response'] = 'Error: ' . $api->errorMessage; } } $this->load->view('ajax/mc_subscribe', $data); }
public function save() { if (!$_POST) { die; } $this->rsp = Response::instance(); if (!valid::email($_POST['email'])) { $this->rsp->msg = 'Invalid Email!'; $this->rsp->send(); } elseif ($this->owner->unique_key_exists($_POST['email'])) { $this->rsp->msg = 'Email already exists!'; $this->rsp->send(); } $pw = text::random('alnum', 8); $this->owner->email = $_POST['email']; $this->owner->password = $pw; $this->owner->save(); $replyto = 'unknown'; $body = "Hi there, thanks for saving your progess over at http://pluspanda.com \r\n" . "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda"; # to do FIX THE HEADERS. $subject = 'Your Pluspanda account information =)'; $headers = "From: welcome@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion(); mail($_POST['email'], $subject, $body, $headers); # add to mailing list. include Kohana::find_file('vendor/mailchimp', 'MCAPI'); $config = Kohana::config('mailchimp'); $mailchimp = new MCAPI($config['apikey']); $mailchimp->listSubscribe($config['list_id'], $_POST['email'], '', 'text', FALSE, TRUE, TRUE, FALSE); $this->rsp->status = 'success'; $this->rsp->msg = 'Thanks, Account Saved!'; $this->rsp->send(); }
function storeAddress($apikey, $listid) { // $your_apikey = '78a6118343c6bf1cdade80bb4162e0b3-us9'; // $my_list_unique_id = "e5cd1cb09f"; $your_apikey = $apikey; $my_list_unique_id = $listid; // 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($your_apikey); // 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 = $my_list_unique_id; if ($api->listSubscribe($list_id, $_GET['email'], '') === true) { // It worked! return 'Success! Check your email to confirm.'; } else { // An error ocurred, return error message return 'Error: ' . $api->errorMessage; } }
function mailChimp($email, $api, $list_id, $messages) { // Retrieve API key from: http://admin.mailchimp.com/account/api/ $api = new MCAPI($api); if ($api->listSubscribe($list_id, $email, '') === true) { // Success! $status = 'success'; $message = $messages[3]; } else { if (empty($email)) { $status = "error"; $message = $messages[0]; } else { if (!preg_match('/^[^\\W][a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/', $email)) { $status = "error"; $message = $messages[1]; } else { // An error ocurred, return error message $status = 'error'; $message = $messages[4]; } } } $data = array('status' => $status, 'message' => $message); echo json_encode($data); exit; }
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('d7229a6dbbe5df2b5bb2f6430fdbefd4-us2'); // 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 = "97aad3ac02"; // Merge variables are the names of all of the fields your mailing list accepts // Ex: first name is by default FNAME // You can define the names of each merge variable in Lists > click the desired list > list settings > Merge tags for personalization // Pass merge values to the API in an array as follows $mergeVars = array('FNAME' => $_GET['fname'], 'LNAME' => $_GET['lname'], 'ADDRESS' => $_GET['address'], 'CITY' => $_GET['city'], 'STATE' => $_GET['state'], 'ZIP' => $_GET['zip']); if ($api->listSubscribe($list_id, $_GET['email'], $mergeVars) === true) { // It worked! return 'Success! Check your email to confirm sign up.'; } else { // An error ocurred, return error message return 'Error: ' . $api->errorMessage; } }
function iron_mailchimp_subscribe() { require_once IRON_PARENT_DIR . '/includes/classes/MCAPI.class.php'; $enabled = get_iron_option('newsletter_enabled'); $mc_api_key = get_iron_option('mailchimp_api_key'); $mc_list_id = get_iron_option('mailchimp_list_id'); extract($_POST); if (!$enabled) { die('disabled'); } if ($mc_api_key == '' || $mc_list_id == '') { die('missing_api_key'); } // check if email is valid if (isset($email) && is_email($email)) { $api = new MCAPI($mc_api_key); if ($api->listSubscribe($mc_list_id, $email, '') === true) { die('success'); } else { die('subscribed'); } } else { die('invalid'); } }
public function actionMailchimp() { if (!isset($_POST['email']) || !$_POST['email']) { echo "No email provided"; $this->redirect(array('/deal/search', 'notify' => 'no_email')); } if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\$/i", $_POST['email'])) { echo "Email address is invalid"; $this->redirect(array('/deal/search', 'notify' => 'invalid_email')); } Yii::import('pages.components.MailChimp.MCAPI'); $path = Yii::getPathOfAlias('pages.components.MailChimp'); require $path . '/MCAPI.php'; // grab an API Key from http://admin.mailchimp.com/account/api/ $api = new MCAPI('fa420eff49d20479854185e4432ee34f-us2'); // 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 = "d95db04d2d"; if ($api->listSubscribe($list_id, $_POST['email'], '', 'html', false, false, true, true) === true) { // It worked! $this->redirect(array('/deal/search', 'notify' => 'success')); } else { // An error ocurred, return error message //echo $api->errorMessage; $this->redirect(array('/deal/search', 'notify' => 'api_error')); } }
public static function getList($params = array()) { require_once OSEMSC_B_LIB . DS . 'MCAPI.class.php'; $oseMscConfig = oseRegistry::call('msc')->getConfig(null, 'obj'); $APIKey = $oseMscConfig->mailchimp_api_key; $api = new MCAPI($APIKey); $lists = $api->lists(); $data = $lists['data']; $items = array(); $item = array(); foreach ($data as $value) { $item['list_id'] = $value['id']; $item['name'] = $value['name']; $items[] = $item; } $result = array(); if (count($items) < 1) { $result['total'] = 0; $result['results'] = ''; } else { $result['total'] = count($items); $result['results'] = $items; } return $result; }
public function getCMSFields() { $fieldBody = new TextareaField('Body', 'Inhoud'); $fieldBody->setRows(5); $oFields = new FieldList(new TextField('Header', 'Title'), $fieldBody, new TextField('FieldLabelName', 'Dummy text in name field'), new TextField('FieldLabelEmail', 'Dummy text in email field'), new TextField('BtnLabel', 'Button label')); if (Config::inst()->get(NewsLetterWidget_Name, NewsLetterWidget_Storage_Sys) == NewsLetterWidget_Storage_Sys_Mailchimp) { $fldTextFieldListId = new TextField('MailChimpListID', 'Mailchimp lijst id'); $sApiKey = Config::inst()->get(NewsLetterWidget_Name, NewsLetterWidget_Storage_Sys_Mailchimp_APIKey); if ($sApiKey == null || trim($sApiKey) == '') { $oFields->push($fldTextFieldListId); } else { // fetch lists $api = new MCAPI($sApiKey); $retval = $api->lists(); if ($api->errorCode) { //echo "Unable to load lists()!"; //echo "\n\tCode=".$api->errorCode; //echo "\n\tMsg=".$api->errorMessage."\n"; } else { //echo "Lists that matched:".$retval['total']."\n"; //echo "Lists returned:".sizeof($retval['data'])."\n"; $aOptions = array(); foreach ($retval['data'] as $list) { //echo "Id = ".$list['id']." - ".$list['name']."\n"; //echo "Web_id = ".$list['web_id']."\n"; $aOptions[$list['id']] = $list['name']; } $oFields->push(new DropdownField('MailChimpListID', 'Mailchimp lijst id', $aOptions)); } } } return $oFields; }
/** * store address to mailchimp mailing list * IMPORTANT : - Replace 'YOUR_APIKEY_HERE' by your api key from your mailchimp Get one here http://admin.mailchimp.com/account/api/ - Replace 'YOUR_LISTID_HERE' by your list's unique ID Create a list here http://admin.mailchimp.com/lists/ Then Click the "settings" link for the list - the Unique Id is at the bottom of that page. */ function storeAddress($user_email) { $m_response = array(); // Validation if (!$user_email) { $m_response['error'] = "No email address provided"; return $m_response; } if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\$/i", $user_email)) { $m_response['error'] = "Email address is invalid"; return $m_response; } require_once 'MCAPI.class.php'; // grab an API Key from http://admin.mailchimp.com/account/api/ $api = new MCAPI('YOUR_APIKEY_HERE'); // 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_LISTID_HERE"; if ($api->listSubscribe($list_id, $user_email, '') === true) { // It worked! $m_response['success'] = 'You will be notified'; //return 'Success! Check your email to confirm sign up.'; } else { // An error ocurred, return error message $m_response['error'] = 'Error: Something went wrong' . $api->errorMessage; //return 'Error: ' . $api->errorMessage; } return $m_response; }
function autoresponder($plan, $user) { $plan_mc_listid = $plan->plan_mc_listid; $plan_mc_groupid = $plan->plan_mc_groupid; $name = $user->get('name'); $email = $user->get('email'); $explodename = explode(' ', "{$name} "); $fname = $explodename[0]; $lname = $explodename[1]; $merge_vars = array('FNAME' => $fname, 'LNAME' => $lname, 'INTERESTS' => $plan_mc_groupid); require_once JPATH_COMPONENT . '/helpers/MCAPI.class.php'; // Get the component config/params object. $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $api_key = $params->get($paramsPrefix . 'MCapi'); $api = new MCAPI($api_key); $api->listSubscribe($plan_mc_listid, $email, $merge_vars); // check for duplicates $db =& JFactory::getDBO(); $sql = 'SELECT COUNT(*)' . ' FROM #__joomailermailchimpintegration' . ' WHERE email = "' . $email . '" AND listid = "' . $plan_mc_listid . '"'; $db->setQuery($sql); $count = $db->loadResult(); if ($count == 0) { // add to joomailermailchimpintegration DB $sql = 'INSERT INTO #__joomailermailchimpintegration' . ' VALUES ("",' . $user->get('id') . ',"' . $email . '","' . $plan_mc_listid . '")'; $db->setQuery($sql); $db->query(); } //joomailermailchimpintegration DB }
function oxy_sign_up() { if (isset($_POST['nonce'])) { if (wp_verify_nonce($_POST['nonce'], 'oxygenna-sign-me-up-nonce')) { header('Content-Type: application/json'); $resp = new stdClass(); $user_email = $_POST['email']; $resp->email = $user_email; if (filter_var($user_email, FILTER_VALIDATE_EMAIL) !== false) { //create the API from the stored key $api = new MCAPI(oxy_get_option('api_key')); // The list the user will subscribe to $list_id = oxy_get_option('list_id'); $api->listSubscribe($list_id, $user_email); if ($api->errorCode) { $resp->status = 'error'; $resp->message = __('Error registering', THEME_FRONT_TD); } else { $resp->status = 'ok'; $resp->message = __('Registered', THEME_FRONT_TD); } } else { $resp->status = 'error'; $resp->message = __('Invalid email', THEME_FRONT_TD); } echo json_encode($resp); die; } } }
function sendMailchimp($formData) { $api = new MCAPI(MAILCHIMP_API_KEY); if ($api->listSubscribe(MAILCHIMP_LIST_ID, $formData['newsletter-email'], '') === true) { return true; } else { return $api->errorMessage; } }
protected function __trigger() { $email = $_POST['email']; $merge = $_POST['merge']; $result = new XMLElement("mailchimp"); $api = new MCAPI($this->_driver->getUser(), $this->_driver->getPass()); $cookies = new XMLElement("cookies"); foreach ($merge as $key => $val) { if (!empty($val)) { $cookie = new XMLElement('cookie', $val); $cookie->setAttribute("handle", $key); $cookies->appendChild($cookie); } } $cookie = new XMLElement('cookie', $email); $cookie->setAttribute("handle", 'email'); $cookies->appendChild($cookie); $result->appendChild($cookies); if ($merge['fname'] == '') { $error = new XMLElement('error', 'First name is required.'); $error->setAttribute("handle", 'fname'); $result->appendChild($error); $result->setAttribute("result", "error"); return $result; } if ($merge['lname'] == '') { $error = new XMLElement('error', 'Last name is required.'); $error->setAttribute("handle", 'lname'); $result->appendChild($error); $result->setAttribute("result", "error"); return $result; } if ($email == '') { $error = new XMLElement('error', 'E-mail is required.'); $error->setAttribute("handle", 'email'); $result->appendChild($error); $result->setAttribute("result", "error"); return $result; } if (!ereg('^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$', $email)) { $error = new XMLElement('error', 'E-mail is invalid.'); $error->setAttribute("handle", 'email'); $result->appendChild($error); $result->setAttribute("result", "error"); return $result; } if (!$api->listSubscribe($this->_driver->getList(), $email, array_change_key_case($merge, CASE_UPPER))) { $result->setAttribute("result", "error"); $error = new XMLElement("error", $api->errorMessage); $result->appendChild($error); } else { $result->setAttribute("result", "success"); } return $result; }
function storeAddress() { $getmailchimp = mysql_query("select api_key, list_id from idevaff_newsletter_mailchimp"); $getmailchimp = mysql_fetch_array($getmailchimp); $mailchimp_key = $getmailchimp['api_key']; $mailchimp_listid = $getmailchimp['list_id']; require_once 'MCAPI.class.php'; $api = new MCAPI($mailchimp_key); $mergeVars = array('FNAME' => quote_smart($_POST['f_name']), 'LNAME' => quote_smart($_POST['l_name'])); $api->listSubscribe($mailchimp_listid, quote_smart($_POST['email']), $mergeVars); }
function sendMailChimp($mailSubscribe) { if (defined('MC_APIKEY') && defined('MC_LISTID')) { $api = new MCAPI(MC_APIKEY); if ($api->listSubscribe(MC_LISTID, $mailSubscribe) !== true) { if ($api->errorCode == 214) { throw new Exception("Email exist", 2); } else { errorLog("MailChimp", "[" . $api->errorCode . "] " . $api->errorMessage); } } } }
function unSubscribe($userId = null, $listId = null, $email = null) { App::import('Vendor', 'MCAPI', array('file' => 'MCAPI.class.php')); $MCapi = new MCAPI(MCLOGIN, MCPASSWORD); $mcListId = $this->field('chimpid', array('id' => $listId)); if (!$mcListId) { return false; } $this->MailinglistUser->deleteAll("mailinglist_id = {$listId} AND user_id = {$userId}"); /*Remove from the list*/ $result = $MCapi->listUnsubscribe($mcListId, $email, true, true, false); //pr($MCapi->errorCode); }
/** * Main AJAX Processor */ function bulldog_newsletter_subscribe_ajax_processor(){ $return = array(); //nonce security check if( empty( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'newsletter-nonce' ) ){ $return['error'] = true; $return['message'] = 'Error: Please contact the site administrator.'; echo json_encode( $return ); exit; } //load MailChimp's MCAPI wrapper require_once( 'MCAPI.class.php' ); //process email address input $email = $_POST['email']; //check if email is valid if( !is_email( $email ) ){ //email is invalid, stop processing and return an error message $return['error'] = true; $return['message'] = 'Please enter a valid e-mail address.'; echo json_encode( $return ); exit; } //get API Key stored in options //grab an API Key from http://admin.mailchimp.com/account/api/ $api_key = of_get_option( 'newsletter-mc-api-key' ); //get Unique List ID stored in options // 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 = of_get_option( 'newsletter-mc-list-id' ); $mc = new MCAPI( $api_key ); $status = $mc->listSubscribe($list_id, $email, ''); if( $status === true ){ $return['error'] = false; $return['message'] = 'Thank you for subscribing to our newsletter! You will receive a confirmation email shortly.'; } else { $return['error'] = true; $return['message'] = 'There was a problem signing you up. Please try again or contact the site administrator.'; } echo json_encode( $return ); exit; }
public function run($args) { $subscribers = User::model()->findAllByAttributes(array('newsletter' => true, 'previous_newsletter_state' => false)); $batch = array(); foreach ($subscribers as $s) { $batch[] = array('EMAIL' => $s->email, 'FNAME' => $s->first_name, 'LNAME' => $s->last_name); $s->previous_newsletter_state = true; $s->save(); } $api = new MCAPI(Yii::app()->params['mc_apikey']); $result = $api->listBatchSubscribe(Yii::app()->params['mc_listID'], $batch, false); if (isset($result['errors'])) { foreach ($result['errors'] as $e) { if ($e['code'] == 212) { //User unsubscribed, need to resubscribe individually $user = User::model()->findByAttributes(array('email' => $e['email'])); if ($user !== null) { $info = array('FNAME' => $user->first_name, 'LNAME' => $user->last_name); $api->listSubscribe(Yii::app()->params['mc_listID'], $user->email, $info); if ($api->errorCode) { echo "Subscribe {$user->email} failed!\n"; echo "code:" . $api->errorCode . "\n"; echo "msg :" . $api->errorMessage . "\n"; } else { echo "Re-Subscribe {$user->email} Successfully\n"; } } } else { if ($e['code'] != 214) { print_r($e); } } } } $unsubscribers = User::model()->findAllByAttributes(array('newsletter' => false, 'previous_newsletter_state' => true)); $batch = array(); foreach ($unsubscribers as $u) { $batch[] = $u->email; $u->previous_newsletter_state = $u->newsletter = 0; $u->save(); } $result = $api->listBatchUnsubscribe(Yii::app()->params['mc_listID'], $batch); if (isset($result['errors'])) { foreach ($result['errors'] as $e) { if ($e['code'] != 215) { print_r($e); } } } }
public function email() { include Kohana::find_file('vendor/mailchimp', 'MCAPI'); $config = Kohana::config('mailchimp'); $mailchimp = new MCAPI($config['apikey']); $owners = ORM::factory('owner')->find_all(); foreach ($owners as $owner) { if (empty($owner->email)) { continue; } echo kohana::debug($mailchimp->listSubscribe($config['list_id'], $owner->email, '', 'text', false, true, true, false)); } die('done'); }
/** * RESIVE INFORMACION DEL FORMULARIO DE CONTACTO */ function ajax_mail_send_newsletter() { $email = isset($_POST['email']) ? $_POST['email'] : ''; $apikey = '148b26f8172e2d50df928c4eca4b46aa-us12'; $listId = 'da8c08262c'; $apiUrl = 'http://api.mailchimp.com/1.3/'; $api = new MCAPI($apikey); $retval = $api->listSubscribe($listId, $email, array(), 'html', false); if ($api->errorCode) { wp_send_json("Hubo un error con la solicitud, intentalo de nuevo."); } else { wp_send_json(1); } }
function outdoor_newsletter_form() { global $wpdb, $outdoor_opt; $form_args = wp_parse_args($_POST['args']); $email = sanitize_email($form_args['newsletters-email']); if (!is_email($email)) { echo wp_json_encode(array('status' => 'fail', 'error' => __('Invalid email address!', 'outdoor'))); exit; } // If MailChimp integration enable if (isset($outdoor_opt['od-mailchimp-enable']) && $outdoor_opt['od-mailchimp-enable'] == true) { $mc_key = isset($outdoor_opt['od-mailchimp-key']) ? $outdoor_opt['od-mailchimp-key'] : ''; $mc_listid = isset($outdoor_opt['od-mailchimp-listid']) ? $outdoor_opt['od-mailchimp-listid'] : ''; if ('' != $mc_key && '' != $mc_listid) { $api = new MCAPI($mc_key); if ($api->listSubscribe($mc_listid, $email) !== true) { if ($api->errorCode == 214) { echo wp_json_encode(array('status' => 'fail', 'error' => __('MailChimp error: Email already exists!', 'outdoor'))); exit; } else { echo wp_json_encode(array('status' => 'fail', 'error' => 'MailChimp error: #' . $api->errorCode . ' ' . $api->errorMessage)); exit; } } else { echo wp_json_encode(array('status' => 'success', 'text' => __('MailChimp: You have successfully subscribed! Thanks!', 'outdoor'))); exit; } } else { echo wp_json_encode(array('status' => 'fail', 'error' => __('MailChimp error: invalid api key or list id', 'outdoor'))); exit; } } else { $exists_email = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$wpdb->od_subscribers} WHERE email='%s'", $email)); if ((int) $exists_email > 0) { echo wp_json_encode(array('status' => 'fail', 'error' => __('Email already exists!', 'outdoor'))); exit; } else { $new_subscriber = $wpdb->insert($wpdb->od_subscribers, array('email' => $email), array('%s')); if ((int) $new_subscriber == 1) { echo wp_json_encode(array('status' => 'success', 'text' => __('You have successfully subscribed! Thanks!', 'outdoor'))); exit; } else { echo wp_json_encode(array('status' => 'fail', 'error' => __('Error, please contact administrator!', 'outdoor'))); exit; } } } }
public function actionSubscribe() { // get post variables $email = craft()->request->getParam('email', ''); $formListId = craft()->request->getParam('lid', ''); $vars = craft()->request->getParam('mcvars', array()); $redirect = craft()->request->getParam('redirect', ''); if ($email != '' && $this->_validateEmail($email)) { // validate email // include mailchimp api class require_once CRAFT_PLUGINS_PATH . 'mailchimpsubscribe/vendor/mcapi/MCAPI.class.php'; // get plugin settings // passes list id from form value lid $settings = $this->_init_settings(); $listIdStr = $formListId != '' ? $formListId : $settings['mcsubListId']; // check if we got an api key and a list id if ($settings['mcsubApikey'] != '' && $listIdStr != '') { // create a new api instance, and subscribe $api = new \MCAPI($settings['mcsubApikey']); // split id string on | in case more than one list id is supplied $listIdArr = explode("|", $listIdStr); // convert groups to input format if present if (isset($vars['group']) && count($vars['group'])) { $vars['GROUPINGS'] = array(); foreach ($vars['group'] as $key => $vals) { $vars['GROUPINGS'][] = array('id' => $key, 'groups' => implode(',', $vals)); } } // loop over list id's and subscribe foreach ($listIdArr as $listId) { $retval = $api->listSubscribe($listId, $email, $vars, $emailType = 'html', $settings['mcsubDoubleOptIn']); } if ($api->errorCode) { // an API error occurred $this->_setMessage($api->errorCode, $email, $vars, $api->errorMessage); } else { // list subscribe was successful $this->_setMessage(200, $email, $vars, "Subscribed successfully", true, $redirect); } } else { // error, no API key or list id $this->_setMessage(2000, $email, $vars, "API Key or List ID not supplied. Check your settings."); } } else { // error, invalid email $this->_setMessage(1000, $email, $vars, "Invalid email"); } }
public function __construct($key = null) { if ($key === null) { $key = trim(file_get_contents($_SERVER['ROOT_DIR'] . '/data/secret/mailchimp-api-key')); } return parent::__construct($key); }
function storeAddress() { $getlastid = mysql_query("select f_name, l_name, email from idevaff_affiliates ORDER BY id DESC"); $getlastid = mysql_fetch_array($getlastid); $f_name = $getlastid['f_name']; $l_name = $getlastid['l_name']; $email = $getlastid['email']; $getmailchimp = mysql_query("select api_key, list_id from idevaff_newsletter_mailchimp"); $getmailchimp = mysql_fetch_array($getmailchimp); $mailchimp_key = $getmailchimp['api_key']; $mailchimp_listid = $getmailchimp['list_id']; require_once 'MCAPI.class.php'; $api = new MCAPI($mailchimp_key); $mergeVars = array('FNAME' => $f_name, 'LNAME' => $l_name); $api->listSubscribe($mailchimp_listid, $email, $mergeVars); }
function MCauth() { if (!isset($_SESSION['MCping'])) { jimport('joomla.html.parameter'); jimport('joomla.application.component.helper'); $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new MCAPI($MCapi); $ping = $MC->ping(); $_SESSION['MCping'] = $ping; } else { $ping = $_SESSION['MCping']; } return $ping; }