public static function donation_button_constant_contact_handler($posted)
 {
     $cc_list_id = get_option("donation_button_constantcontact_lists");
     $cc_api_key = get_option("constantcontact_api_key");
     $access_token = get_option("constantcontact_access_token");
     $fname = isset($posted['first_name']) ? $posted['first_name'] : '';
     $lname = isset($posted['last_name']) ? $posted['last_name'] : '';
     $email = isset($posted['payer_email']) ? $posted['payer_email'] : $posted['receiver_email'];
     $debug = get_option('log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     if (isset($cc_api_key) && !empty($cc_api_key) && (isset($access_token) && !empty($access_token)) && (isset($cc_list_id) && !empty($cc_list_id))) {
         try {
             $ConstantContact = new ConstantContact($cc_api_key);
             $response = $ConstantContact->getContactByEmail($access_token, $email);
             if (empty($response->results)) {
                 $Contact = new Contact();
                 $Contact->addEmail($email);
                 $Contact->addList($cc_list_id);
                 $Contact->first_name = $fname;
                 $Contact->last_name = $lname;
                 $NewContact = $ConstantContact->addContact($access_token, $Contact, false);
                 if (isset($NewContact) && 'yes' == $debug) {
                     $log->add('ConstantContact', ' ConstantContact new contact ' . $email . ' added to selected contact list');
                 }
             } else {
                 $Contact = $response->results[0];
                 $Contact->first_name = $fname;
                 $Contact->last_name = $lname;
                 $Contact->addList($cc_list_id);
                 $new_contact = $ConstantContact->updateContact($access_token, $Contact, false);
                 if (isset($new_contact) && 'yes' == $debug) {
                     $log->add('ConstantContact', ' ConstantContact update contact ' . $email . ' to selected contact list');
                 }
             }
         } catch (CtctException $ex) {
             $error = $ex->getErrors();
             $log->add('ConstantContact', print_r($error, true));
         }
     } else {
         if ('yes' == $debug) {
             $log->add('ConstantContact', 'Constant Contact API Key OR Constant Contact Access Token does not set');
         }
     }
 }
Exemple #2
0
function annadir_newsletter($mail = false)
{
    $handle = new Mensajes();
    $mail = (string) $mail;
    if (!$mail || !is_email($mail)) {
        $handle->add_error('No se ha recibido un mail válido');
    } else {
        require_once '../classes/php-sdk-development/src/Ctct/autoload.php';
        $cc = new ConstantContact(APIKEY_CONSTANT);
        $contacts = $cc->getContacts(ACCESS_TOKEN_CONSTANT);
        $lists = $cc->getLists(ACCESS_TOKEN_CONSTANT);
        $list = '2021474646';
        try {
            $response = $cc->getContactByEmail(ACCESS_TOKEN_CONSTANT, $mail);
            if (empty($response->results)) {
                $contact = new Contact();
                $contact->addEmail($mail);
                $contact->addList($list);
                $returnContact = $cc->addContact(ACCESS_TOKEN_CONSTANT, $contact, true);
            } else {
                $contact = $response->results[0];
                $contact->addList($list);
                $returnContact = $cc->updateContact(ACCESS_TOKEN_CONSTANT, $contact, true);
            }
            $handle->add_mensaje('Tu correo se ha añadido correctamente a la lista de Bunch of Makers');
        } catch (CtctException $ex) {
            $errores = reset($ex->getErrors());
            $handle->add_error($errores['error_message']);
        }
    }
    return $handle->imprimir(false, true) . '<script>finalizar_subscripcion();</script>';
}
Exemple #3
0
 /**
  * 
  * 
  */
 public function addContact($listId, $email, $firstName, $lastName, $additional = array())
 {
     try {
         $contact = new Contact();
         $contact->addEmail($email);
         $contact->addList($listId);
         $contact->first_name = $firstName;
         $contact->last_name = $lastName;
         $this->cc->addContact($this->accessToken, $contact);
         return true;
     } catch (CtctException $ex) {
         $error = (array) $ex->getErrors();
         $this->_errorMessage = $error[0]['error_message'];
         return false;
     }
 }
 /**
  * @since   1.2.0
  * @param type $posted
  * @return type
  */
 public static function ofw_constantcontact_handler($posted)
 {
     if (!isset($posted) || empty($posted)) {
         return;
     }
     $debug = get_option('ofw_log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         require_once 'class-offers-for-woocommerce-logger.php';
         $log = new Angelleye_Offers_For_Woocommerce_Logger();
     }
     $concontact_api_key = get_option('ofw_constantcontact_api_key');
     $constantcontact_access_token = get_option('ofw_constantcontact_access_token');
     $cclistsid = get_option('ofw_constantcontact_lists');
     $first_name = isset($posted['offer_name']) ? $posted['offer_name'] : '';
     $last_name = '';
     $offer_email = isset($posted['offer_email']) ? $posted['offer_email'] : '';
     if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
         $ConstantContact = new ConstantContact($concontact_api_key);
         $response = $ConstantContact->getContactByEmail($constantcontact_access_token, $offer_email);
         if (empty($response->results)) {
             $Contact = new Contact();
             $Contact->addEmail($offer_email);
             $Contact->first_name = $first_name;
             $Contact->last_name = $last_name;
             $Contact->addList($cclistsid);
             $NewContact = $ConstantContact->addContact($constantcontact_access_token, $Contact, false);
             if ('yes' == $debug) {
                 $log->add('ConstantContact', 'ConstantContact new contact ' . $offer_email . ' added to selected contact list');
             }
         } else {
             $Contact = $response->results[0];
             $Contact->first_name = $first_name;
             $Contact->last_name = $last_name;
             $Contact->addList($cclistsid);
             $new_contact = $ConstantContact->updateContact($constantcontact_access_token, $Contact, false);
             $log->add('ConstantContact', 'ConstantContact update contact ' . $offer_email . ' to selected contact list');
         }
     } else {
         if ('yes' == $debug) {
             $log->add('ConstantContact', 'Constant Contact API Key OR Constant Contact Access Token does not set');
         }
     }
 }
Exemple #5
0
 /**
  * 
  * 
  */
 public function addContact($email, $firstName, $lastName, $lists = array(), $additional = array(), $actualUser = true)
 {
     try {
         $contact = new Contact();
         $contact->addEmail($email);
         foreach ($lists as $v) {
             $contact->addList($v);
         }
         $contact->first_name = $firstName;
         $contact->last_name = $lastName;
         !empty($additional['company']) ? $contact->company_name = $additional['company'] : false;
         !empty($additional['job_title']) ? $contact->job_title = $additional['job_title'] : false;
         !empty($additional['work_phone']) ? $contact->work_phone = $additional['work_phone'] : false;
         //$contact->addAddress(Address::create( array("address_type"=>"BUSINESS","line1"=>$street,"city"=>$city,"state"=>$state,"postal_code"=>$zip)));
         $this->cc->addContact($this->accessToken, $contact, $actualUser);
         return true;
     } catch (CtctException $ex) {
         $error = (array) $ex->getErrors();
         $this->_errorMessage = $error[0]['error_message'];
         return false;
     }
 }
} catch (CtctException $ex) {
    foreach ($ex->getErrors() as $error) {
        print_r($error);
    }
}
// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
    $action = "Getting Contact By Email Address";
    try {
        // check to see if a contact with the email addess already exists in the account
        $response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['email']);
        // create a new contact if one does not exist
        if (empty($response->results)) {
            $action = "Creating Contact";
            $contact = new Contact();
            $contact->addEmail($_POST['email']);
            $contact->addList($_POST['list']);
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];
            /*
             * The third parameter of addContact defaults to false, but if this were set to true it would tell Constant
             * Contact that this action is being performed by the contact themselves, and gives the ability to
             * opt contacts back in and trigger Welcome/Change-of-interest emails.
             *
             * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
             */
            $returnContact = $cc->addContact(ACCESS_TOKEN, $contact, false);
            // update the existing contact if address already existed
        } else {
            $action = "Updating Contact";
            $contact = $response->results[0];
function wpcc_add_contact()
{
    $cc = new ConstantContact(WPCC_APIKEY);
    try {
        $lists = $cc->listService->getLists(WPCC_ACCESS_TOKEN);
    } catch (CtctException $ex) {
        foreach ($ex->getErrors() as $error) {
            print_r($error);
        }
        if (!isset($lists)) {
            $lists = null;
        }
    }
    // check if the form was submitted
    if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
        $action = "Getting Contact By Email Address";
        try {
            // check to see if a contact with the email address already exists in the account
            $response = $cc->contactService->getContacts(WPCC_ACCESS_TOKEN, array("email" => $_POST['email']));
            // create a new contact if one does not exist
            if (empty($response->results)) {
                $action = "Creating Contact";
                $contact = new Contact();
                $contact->addEmail($_POST['email']);
                $contact->addList('1818691277');
                $contact->first_name = $_POST['first_name'];
                $contact->last_name = $_POST['last_name'];
                $address = new Address();
                $address->address_type = "BUSINESS";
                // PERSONAL, BUSINESS, UNKNOWN
                $address->line1 = $_POST['address_line_1'];
                $address->line2 = $_POST['address_line_2'];
                $address->city = $_POST['city'];
                $address->state_code = $_POST['state_code'];
                $address->postal_code = $_POST['postal_code'];
                $address->country_code = "US";
                $contact->addAddress($address);
                $returnContact = $cc->contactService->addContact(WPCC_ACCESS_TOKEN, $contact);
            } else {
                $action = "Updating Contact";
                $contact = $response->results[0];
                if ($contact instanceof Contact) {
                    $contact->addList('1818691277');
                    $contact->first_name = $_POST['first_name'];
                    $contact->last_name = $_POST['last_name'];
                    //If address exists, update that address. Else, create a new address object.
                    if (count($contact->addresses) > 0) {
                        $address = $contact->addresses[0];
                    } else {
                        $address = new Address();
                    }
                    $address->address_type = "BUSINESS";
                    // PERSONAL, BUSINESS, UNKNOWN
                    $address->line1 = $_POST['address_line_1'];
                    $address->line2 = $_POST['address_line_2'];
                    $address->city = $_POST['city'];
                    $address->state = '';
                    $address->state_code = $_POST['state_code'];
                    $address->postal_code = $_POST['postal_code'];
                    $address->country_code = $_POST['country_code'];
                    $contact->addAddress($address);
                    $customField_1 = new CustomField();
                    $customField_1->name = "CustomField1";
                    $customField_1->value = date('m/d/y', strtotime($_POST['dob']));
                    $contact->addCustomField($customField_1);
                    /*
                     * The third parameter of updateContact defaults to false, but if this were set to true it would tell
                     * Constant Contact that this action is being performed by the contact themselves, and gives the ability to
                     * opt contacts back in and trigger Welcome/Change-of-interest emails.
                     *
                     * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
                     */
                    $returnContact = $cc->contactService->updateContact(WPCC_ACCESS_TOKEN, $contact);
                } else {
                    $e = new CtctException();
                    $e->setErrors(array("type", "Contact type not returned"));
                    throw $e;
                }
            }
            // catch any exceptions thrown during the process and print the errors to screen
        } catch (CtctException $ex) {
            echo '<span class="label label-important">Error ' . $action . '</span>';
            echo '<div class="container alert-error"><pre class="failure-pre">';
            print_r($ex->getErrors());
            echo '</pre></div>';
            die;
        }
    }
}
 /**
  * Añade un mail al newsletter
  *
  * @param bool|string $mail mail que será añadido al newsletter.
  * @return string mensaje de error o de éxito.
  * @throws Exception si el algún setting del Newsletter no ha sido configurado.
  */
 public static function Add($mail = false)
 {
     global $mensaje;
     $mail = (string) $mail;
     if (!$mail || filter_var($mail, FILTER_VALIDATE_EMAIL) === false) {
         $mensaje->add_error('No se ha recibido un mail válido');
     } else {
         try {
             $cc = new ConstantContact(NewsletterHelper::ApiKey());
             $list = NewsletterHelper::ListNumber();
             $response = $cc->contactService->getContacts(NewsletterHelper::AccessToken(), array('email' => $mail));
             // Parameters
             $actionByVisitor = true;
             $params = array();
             if ($actionByVisitor == true) {
                 $params['action_by'] = "ACTION_BY_VISITOR";
             }
             if (empty($response->results)) {
                 $contact = new Contact();
                 $contact->addEmail($mail);
                 $contact->addList($list);
                 $returnContact = $cc->contactService->addContact(NewsletterHelper::AccessToken(), $contact, $params);
             } else {
                 /**
                  * @var $contact Contact
                  */
                 $contact = $response->results[0];
                 $contact->addList($list);
                 $returnContact = $cc->contactService->updateContact(NewsletterHelper::AccessToken(), $contact, $params);
             }
             $mensaje->add_mensaje('Tu correo se ha añadido correctamente a la lista');
         } catch (Exception $ex) {
             if ($ex instanceof CtctException) {
                 $allErrors = $ex->getErrors();
                 $errores = reset($allErrors);
                 $mensaje->add_error($errores->error_message);
             } else {
                 $mensaje->add_error($ex->getMessage());
             }
         }
     }
 }
<?php

require_once 'Ctct/autoload.php';
define("APIKEY", $options_array['constant_contact']['api_key']);
define("ACCESS_TOKEN", $options_array['constant_contact']['access_token']);
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;
$cc = new ConstantContact(APIKEY);
try {
    $response = $cc->getContactByEmail(ACCESS_TOKEN, $email);
    if (empty($response->results)) {
        $action = "Creating Contact";
        $contact = new Contact();
        $contact->addEmail($email);
        $contact->addList($constant_contact_list);
        $contact->first_name = $fname;
        $contact->last_name = $lname;
        $returnContact = $cc->addContact(ACCESS_TOKEN, $contact, false);
    } else {
        $action = "Updating Contact";
        $contact = $response->results[0];
        $contact->addList($constant_contact_list);
        $contact->first_name = $fname;
        $contact->last_name = $lname;
        $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, false);
    }
} catch (CtctException $ex) {
}
 /**
  * Añade un mail al newsletter
  *
  * @param bool|string $mail mail que será añadido al newsletter.
  * @return string mensaje de error o de éxito.
  * @throws Exception si el algún setting del Newsletter no ha sido configurado.
  */
 public static function Add($mail = false)
 {
     $handle = new Mensajes();
     $mail = (string) $mail;
     if (!$mail || !is_email($mail)) {
         $handle->add_error('No se ha recibido un mail válido');
     } else {
         require_once '../php-sdk-development/src/Ctct/autoload.php';
         $cc = new ConstantContact(NewsletterHelper::ApiKey());
         $list = NewsletterHelper::ListNumber();
         try {
             $response = $cc->getContactByEmail(NewsletterHelper::AccessToken(), $mail);
             if (empty($response->results)) {
                 $contact = new Contact();
                 $contact->addEmail($mail);
                 $contact->addList($list);
                 $returnContact = $cc->addContact(NewsletterHelper::AccessToken(), $contact, true);
             } else {
                 $contact = $response->results[0];
                 $contact->addList($list);
                 $returnContact = $cc->updateContact(NewsletterHelper::AccessToken(), $contact, true);
             }
             $handle->add_mensaje('Tu correo se ha añadido correctamente a la lista');
         } catch (CtctException $ex) {
             $errores = reset($ex->getErrors());
             $handle->add_error($errores['error_message']);
         }
     }
     return $handle->imprimir(false, true);
     //.'<script>finalizar_subscripcion();</script>';
 }
 /**
  * Añade un mail al newsletter
  *
  * @param bool|string $mail mail que será añadido al newsletter.
  * @return string mensaje de error o de éxito.
  * @throws Exception si el algún setting del Newsletter no ha sido configurado.
  */
 public static function Add($mail = false)
 {
     global $mensaje;
     $mail = (string) $mail;
     if (!$mail || !is_email($mail)) {
         $mensaje->add_error('No se ha recibido un mail válido');
     } else {
         try {
             $cc = new ConstantContact(NewsletterHelper::ApiKey());
             $list = NewsletterHelper::ListNumber();
             $response = $cc->getContactByEmail(NewsletterHelper::AccessToken(), $mail);
             if (empty($response->results)) {
                 $contact = new Contact();
                 $contact->addEmail($mail);
                 $contact->addList($list);
                 $returnContact = $cc->addContact(NewsletterHelper::AccessToken(), $contact, true);
             } else {
                 $contact = $response->results[0];
                 $contact->addList($list);
                 $returnContact = $cc->updateContact(NewsletterHelper::AccessToken(), $contact, true);
             }
             $mensaje->add_mensaje('Tu correo se ha añadido correctamente a la lista');
         } catch (Exception $ex) {
             if ($ex instanceof CtctException) {
                 $errores = reset($ex->getErrors());
                 $mensaje->add_error($errores['error_message']);
             } else {
                 $mensaje->add_error($ex->getMessage());
             }
         }
     }
 }
 public function subscribe()
 {
     if (!$this->getRequest()->isAjax()) {
         //if not ajax, say go and eat your grass.
         exit("Action is not allowed!");
     }
     $return = array('action' => '', 'message' => '');
     $config = SiteConfig::current_site_config();
     $cc = new ConstantContact($config->CcApiKey);
     $list = $this->getRequest()->postVar('list');
     if ($config->CcDisplayZip) {
         $postcode = array('postal_code' => $this->getRequest()->postVar('postcode'));
     } else {
         $postcode = 0;
     }
     $email = $this->getRequest()->postVar('email');
     $first_name = $this->getRequest()->postVar('first_name');
     $last_name = $this->getRequest()->postVar('last_name');
     if (empty($email) || empty($first_name) || empty($last_name) || empty($list)) {
         $return['action'] = 'E';
         $return['message'] = $config->CcRequiredMessage ? $config->CcRequiredMessage : 'Required fields are missing.';
     } else {
         try {
             // check to see if a contact with the email addess already exists in the account
             $response = $cc->getContactByEmail($config->CcAccessToken, $email);
             // create a new contact if one does not exist
             if (empty($response->results)) {
                 $return['action'] = "C";
                 $contact = new Contact();
                 $contact->addEmail($email);
                 if (!is_array($list)) {
                     $contact->addList($list);
                 } else {
                     foreach ($list as $l) {
                         $contact->addList($l);
                     }
                 }
                 $contact->first_name = $first_name;
                 $contact->last_name = $last_name;
                 if ($postcode) {
                     $contact->addAddress($postcode);
                 }
                 $returnContact = $cc->addContact($config->CcAccessToken, $contact);
                 if (!empty($returnContact)) {
                     $return['message'] = $config->CcAddedMessage;
                 }
                 // update the existing contact if address already existed
             } else {
                 $return['action'] = "U";
                 $contact = $response->results[0];
                 if (!is_array($list)) {
                     $contact->addList($list);
                 } else {
                     foreach ($list as $l) {
                         $contact->addList($l);
                     }
                 }
                 $contact->first_name = $first_name;
                 $contact->last_name = $last_name;
                 if ($postcode) {
                     $contact->addAddress($postcode);
                 }
                 $returnContact = $cc->updateContact($config->CcAccessToken, $contact);
                 if (!empty($returnContact)) {
                     $return['message'] = $config->CcUpdatedMessage;
                 }
             }
             // catch any exceptions thrown during the process and print the errors to screen
         } catch (CtctException $ex) {
             $ex = $ex->getErrors();
             print_r($ex);
             $return['action'] = 'E';
             $return['message'] = $config->CcErrorMessage;
         }
     }
     return json_encode($return);
 }
 public function contactEntry($first_name, $last_name, $email)
 {
     try {
         // test to see if all the settings are correct
         if ($this->ready()) {
             // check to see if a contact with the email address already exists in the account
             $response = $this->cc->getContactByEmail(ACCESS_TOKEN, $email);
             // create a new contact if one does not exist
             if (empty($response->results)) {
                 $contact = new Contact();
                 $contact->addEmail($email);
                 $contact->addList($this->list);
                 $contact->first_name = $first_name;
                 $contact->last_name = $last_name;
                 $returnContact = $this->cc->addContact(ACCESS_TOKEN, $contact, false);
             } else {
                 $contact = $response->results[0];
                 $contact->addList($this->list);
                 $contact->first_name = $first_name;
                 $contact->last_name = $last_name;
                 $returnContact = $this->cc->updateContact(ACCESS_TOKEN, $contact, false);
             }
             $this->error = false;
         }
     } catch (CtctException $ex) {
         $this->error = true;
     }
     return $this->error;
 }
 public function constantcontact($service, $email)
 {
     $apikey = $service['thekey'];
     $service['additional'] = json_decode($service['additional'], 1);
     $access_token = $service['additional']['access_token'];
     $listId = $service['list'];
     $cc = new ConstantContact($apikey);
     $contact = new Contact();
     $contact->addEmail($email);
     $contact->addList($listId);
     $contact->status = 'ACTIVE';
     $cc->contactService->addContact($access_token, $contact);
     echo "ok";
     die;
 }
 function addContact($data, $list_id = false)
 {
     $errors = array();
     $cc = new ConstantContact(ConstantContactV2::$cckey);
     // attempt to fetch lists in the account, catching any exceptions
     try {
         $lists = $cc->getLists(ConstantContactV2::$cctoken);
     } catch (CtctException $ex) {
         foreach ($ex->getErrors() as $error) {
             $errors[] = $error;
         }
     }
     // get list from the params, or just the first ACTIVE list if no param was passed
     $the_list = false;
     foreach ($lists as $list) {
         if (!$the_list && $list->status == 'ACTIVE') {
             $the_list = $list;
         }
         if ($list_id == $list->id) {
             $the_list = $list;
             break;
         }
     }
     try {
         if ($the_list) {
             $response = $cc->getContactByEmail(ConstantContactV2::$cctoken, $data['email']);
             //If the contact doesn't exist, add.  If it does, update.
             if (empty($response->results)) {
                 $contact = new Contact();
                 $contact->addEmail($data['email']);
                 $contact->addList($the_list->id);
                 $contact->first_name = $data['first_name'];
                 $contact->last_name = $data['last_name'];
                 /*
                  * The third parameter of addContact defaults to false, but if this were set to true it would tell Constant
                  * Contact that this action is being performed by the contact themselves, and gives the ability to
                  * opt contacts back in and trigger Welcome/Change-of-interest emails.
                  *
                  * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
                  */
                 $returnContact = $cc->addContact(ConstantContactV2::$cctoken, $contact, false);
                 return true;
             } else {
                 $contact = $response->results[0];
                 $contact->addList($the_list->id);
                 $contact->first_name = $data['first_name'];
                 $contact->last_name = $data['last_name'];
                 /*
                  * The third parameter of updateContact defaults to false, but if this were set to true it would tell
                  * Constant Contact that this action is being performed by the contact themselves, and gives the ability to
                  * opt contacts back in and trigger Welcome/Change-of-interest emails.
                  *
                  * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
                  */
                 $returnContact = $cc->updateContact(ConstantContactV2::$cctoken, $contact, false);
                 return true;
             }
         }
     } catch (CtctException $ex) {
         /*echo '<pre>';
         		print_r($ex->getErrors());
         		echo '</pre>';
         		die();*/
         $errors[] = $ex->getErrors();
     }
     return $errors;
 }
 public function addEmailToNewsLetter()
 {
     if ($this->request->is('POST') || $this->request->is('PUT')) {
         $api_key = Configure::read('constant_contact_key');
         $api_token = Configure::read('constant_contact_token');
         $cc = new ConstantContact($api_key);
         // attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
         try {
             $lists = $cc->getLists($api_token);
         } catch (Exception $ex) {
             throw new Exception();
         }
         // check if the form was submitted
         $action = "Getting Contact By Email Address";
         try {
             // check to see if a contact with the email addess already exists in the account
             $response = $cc->getContactByEmail($api_token, $_POST['data']['email']);
             // create a new contact if one does not exist
             if (empty($response->results)) {
                 $action = "Creating Contact";
                 $contact = new Contact();
                 $contact->addEmail($_POST['data']['email']);
                 $contact->addList('1339315632');
                 $contact->first_name = $_POST['data']['first_name'];
                 $contact->last_name = $_POST['data']['last_name'];
                 /*
                  * The third parameter of addContact defaults to false, but if this were set to true it would tell Constant Contact that this action is being performed by the contact themselves, and gives the ability to opt contacts back in and trigger Welcome/Change-of-interest emails. See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
                  */
                 $returnContact = $cc->addContact($api_token, $contact, true);
                 // update the existing contact if address already existed
             } else {
                 $action = "Updating Contact";
                 $contact = $response->results[0];
                 $contact->addList('1339315632');
                 $contact->first_name = $_POST['data']['first_name'];
                 $contact->last_name = $_POST['data']['last_name'];
                 $returnContact = $cc->updateContact($api_token, $contact, true);
             }
             // catch any exceptions thrown during the process and print the errors to screen
         } catch (Exception $ex) {
             $this->Session->setFlash('ニュースレターの配信登録に失敗しました。お問い合わせください。', 'default', array('class' => 'message error'));
             $this->redirect('/');
             exit;
         }
         if ($returnContact) {
             $this->Session->setFlash('ニュースレターの配信登録を完了しました。', 'default', array('class' => 'message success'));
             $this->redirect('/');
         }
         exit;
     } else {
         throw new Exception();
     }
 }