Пример #1
0
 public function mailChimpSubscribe($data)
 {
     if (!$data['email']) {
         return "No email address provided";
     }
     if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\$/i", $data['email'])) {
         return "Email address is invalid";
     }
     require_once '/home/icdigyfv/htdocs/admin/inc/klassen/mailChimpApi.inc.php';
     $api = new MCAPI($this->mailChimpApiKey);
     $merge_vars = array('FNAME' => $data['name'], 'LNAME' => $data['surname']);
     if (in_array(1, $data['group'])) {
         if ($api->listSubscribe('0eff6ba7d7', $data['email'], $merge_vars) === true) {
             $response = 'Vielen Dank für Ihre Anmeldung. Sie erhalten in kürze eine E-Mail.';
         } else {
             $response = 'Deine E-Mail Adresse ist schon im Newsletter eingetragen!';
         }
     }
     if (in_array(2, $data['group'])) {
         if ($api->listSubscribe('057fda416a', $data['email'], $merge_vars) === true) {
             $response = 'Vielen Dank für Ihre Anmeldung. Sie erhalten in kürze eine E-Mail.';
         } else {
             $response = 'Deine E-Mail Adresse ist schon im Newsletter eingetragen!';
         }
     }
     return $response;
 }
Пример #2
0
 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);
 }
Пример #3
0
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;
    }
}
Пример #4
0
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;
    }
}
Пример #5
0
 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;
     }
 }
 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'));
     }
 }
Пример #7
0
/**
* 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;
}
Пример #8
0
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');
    }
}
Пример #9
0
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;
}
Пример #10
0
 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();
 }
Пример #11
0
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;
        }
    }
}
Пример #12
0
 /**
  * Subscribe an e-mail to a list.
  * 
  * @param int $listId The id of the list to subscribe to
  * @param string $email The email address to subscribe.
  * @return bool True if email was subscribed successfully.
  */
 public function subscribe($listId, $email)
 {
     // Clear the cache for members in list
     $cacheName = $this->__getCacheName('list_subscribed_members', array($listId));
     $this->__clearMailchimpCache($cacheName);
     return $this->__api->listSubscribe($listId, $email);
 }
Пример #13
0
 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 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
 }
Пример #15
0
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;
    }
}
Пример #16
0
 function widget($args, $instance)
 {
     $data = $this->data;
     $instance['title'] = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     if (isset($_POST['zn_mc_email'])) {
         if (isset($data['mailchimp_api']) && !empty($data['mailchimp_api'])) {
             if (!class_exists('MCAPI')) {
                 include_once TEMPLATEPATH . '/widgets/mailchimp/MCAPI.class.php';
             }
             $api_key = $data['mailchimp_api'];
             $mcapi = new MCAPI($api_key);
             $merge_vars = array('EMAIL' => $_POST['zn_mc_email']);
             $list_id = $instance['zn_mailchimp_list'];
             if ($mcapi->listSubscribe($list_id, $_POST['zn_mc_email'], $merge_vars)) {
                 // It worked!
                 $msg = '<span style="color:green;">' . __('Success!&nbsp; Check your inbox or spam folder for a message containing a confirmation link.', THEMENAME) . '</span>';
             } else {
                 // An error ocurred, return error message
                 $msg = '<span style="color:red;"><b>' . __('Error:', THEMENAME) . '</b>&nbsp; ' . $mcapi->errorMessage . '</span>';
             }
         }
     }
     if (empty($data['mailchimp_api'])) {
         echo '<div class="newsletter-signup">';
         echo '<p>No mailchimp list selected. Please set your mailchimp API key in the theme admin panel and then configure the widget from the widget options.</p>';
         echo '	</div><!-- end newsletter-signup -->';
         return;
     }
     echo $args['before_widget'];
     echo '<div class="newsletter-signup">';
     if (!empty($instance['title'])) {
         echo $args['before_title'] . $instance['title'] . $args['after_title'];
     }
     // GET INTRO TEXT
     if (!empty($instance['zn_mailchimp_intro'])) {
         echo '<p>' . $instance['zn_mailchimp_intro'] . '</p>';
     }
     $button_text = !empty($instance['button_text']) ? $instance['button_text'] : __("JOIN US", THEMENAME);
     echo '		<form method="post" class="newsletter_subscribe newsletter-signup" data-url="' . trailingslashit(home_url()) . '" name="newsletter_form">';
     echo '			<input type="text" name="zn_mc_email" class="nl-email" value="" placeholder="' . __("*****@*****.**", THEMENAME) . '" />';
     echo '			<input type="hidden" name="zn_list_class" class="nl-lid" value="' . $instance['zn_mailchimp_list'] . '" />';
     echo '			<input type="submit" name="submit" class="nl-submit" value="' . $button_text . '" />';
     echo '		</form>';
     if (isset($msg)) {
         echo '<span class="zn_mailchimp_result">' . $msg . '</span>';
     } else {
         echo '		<span class="zn_mailchimp_result"></span>';
     }
     // GET INTRO TEXT
     if (!empty($instance['zn_mailchimp_outro'])) {
         echo '<p>' . $instance['zn_mailchimp_outro'] . '</p>';
     }
     echo '	</div><!-- end newsletter-signup -->';
     echo $args['after_widget'];
     //global $data;
     //print_r($data);
 }
Пример #17
0
 public function moveSubscriber()
 {
     $api = new MCAPI($this->_apiKey);
     $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'];
             }
         }
         if ($api->errorCode != '') {
             // an error occurred while logging in
             Mage::log('Error Code: ' . $api->errorCode);
             Mage::log('Error Message: ' . $api->errorMessage);
             die;
         }
         $retval = $api->listMembers($prospectListId, 'subscribed', null, 0, 10000);
         //var_dump($retval);die;
         if (!$retval) {
             Mage::log('Error Code: ' . $api->errorCode);
             Mage::log('Error Message: ' . $api->errorMessage);
         } else {
             foreach ($retval['data'] as $member) {
                 //echo $member['email']." - ".$member['timestamp']."<br />";
                 $customerModel = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('email', $member['email'])->setPage(1, 1);
                 $customers = $customerModel->getData();
                 $customerId = $customers[0]['entity_id'];
                 $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter('customer_id', $customerId)->getData();
                 if (!empty($orders)) {
                     //if ($member['email'] === '*****@*****.**') {
                     $memInfo = $api->listMemberInfo($prospectListId, array($member['email']));
                     $firstname = $memInfo['data'][0]['merges']['FNAME'];
                     if (empty($firstname)) {
                         $firstname = Mage::getModel('customer/customer')->load($customerId)->getFirstname();
                     }
                     $retuns = $api->listUnsubscribe($prospectListId, $member['email'], 1);
                     if (!$retuns) {
                         Mage::log('Unsubscribe Error Code: ' . $api->errorCode);
                         Mage::log('Unsubscribe Error Message: ' . $api->errorMessage);
                     }
                     $merge_vars = array('FNAME' => $firstname);
                     $retsub = $api->listSubscribe($customerListId, $member['email'], $merge_vars);
                     if (!$retsub) {
                         Mage::log('Subscribe Error Code: ' . $api->errorCode);
                         Mage::log('Subscribe Error Message: ' . $api->errorMessage);
                     }
                     //}
                 }
             }
         }
     }
 }
Пример #18
0
 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;
 }
Пример #19
0
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);
            }
        }
    }
}
/**
 * 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;
}
Пример #22
0
 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);
             }
         }
     }
 }
Пример #23
0
/**
 * 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);
    }
}
Пример #24
0
 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');
 }
 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");
     }
 }
Пример #26
0
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;
            }
        }
    }
}
Пример #27
0
 function subscribe($userId = null, $listId = null, $email = null, $params = array())
 {
     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;
     }
     $params['IP_Address'] = $_SERVER['REMOTE_ADDR'];
     $this->MailinglistUser->deleteAll("mailinglist_id = {$listId} AND user_id = {$userId}");
     $this->MailinglistUser->create();
     $this->MailinglistUser->save(array("mailinglist_id" => $listId, "user_id" => $userId));
     $result = $MCapi->listSubscribe($mcListId, $email, $params, 'html', false, true, true, false);
     //pr($MCapi->errorCode);
     return $result;
 }
Пример #28
0
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 storeAddress()
{
    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';
    $api = new MCAPI($_GET['_mailchimp_key']);
    $list_id = $_GET['_mailchimp_list'];
    if ($api->listSubscribe($list_id, $_GET['email'], '') === true) {
        return 'Success! Check your email to confirm sign up.';
    } else {
        return 'Error: ' . $api->errorMessage;
    }
}
function storeAddress()
{
    //Mailchimp list unique IDs
    //In order of checkboxes on form
    $ids = array('gsv-newsletter-a-to-apple' => 'e901ee2b08', 'gsv-newsletter-socially-mobile-weekly' => '4be882acb0', 'gsv-newsletter-gsv-green-daily' => '930f2aad7a', 'gsv-newsletter-gsv-media-daily' => '', 'gsv-newsletter-gsv-edu-daily' => 'dd52118c89', 'gsv-newsletter-ipo-weekly' => '', 'gsv-newsletter-gsv-blog-moving-ideas' => '5d135222e2');
    $names = explode(' ', $_REQUEST['gsv-newsletter-signup-flyout-form-name']);
    $merge_vars = array('FNAME' => $names[0], 'LNAME' => $names[1]);
    //print_r($_REQUEST);
    // Validation
    if (!$_GET['gsv-newsletter-signup-flyout-form-email']) {
        return "No email address provided";
    }
    if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\$/i", $_GET['gsv-newsletter-signup-flyout-form-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('ba54b579d533805e3a965c7d97607192-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.
    foreach ($_REQUEST as $list => $value) {
        if ($list != 'ajax' && $list != 'gsv-newsletter-signup-flyout-form-name' && $list != 'gsv-newsletter-signup-flyout-form-email' && $list != '__utma' && $list != '__utmz') {
            if ($value == 'on') {
                $list_id = $ids[$list];
                if ($api->listSubscribe($list_id, $_GET['gsv-newsletter-signup-flyout-form-email'], $merge_vars) === true) {
                    // It worked!
                    echo 'Success! Check your email to confirm sign up.';
                } else {
                    // An error ocurred, return error message
                    echo 'Error: ' . $api->errorMessage;
                }
            }
        }
    }
    /*	
    $list_id = "e901ee2b08";
    if($api->listSubscribe($list_id, $_GET['gsv-newsletter-signup-flyout-form-email'], $merge_vars) === true) {
    	// It worked!	
    	echo 'Success! Check your email to confirm sign up.';
    }else{
    	// An error ocurred, return error message	
    	echo 'Error: ' . $api->errorMessage;
    }
    */
}