Beispiel #1
0
             }
         }
     }
     if (isset($email) && strlen($email) > 1 && $list_id != null) {
         $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($CC_ACCESS_TOKEN, $email);
             // create a new contact if one does not exist
             if (empty($response->results)) {
                 $action = "Creating Contact";
                 $contact = new Ctct\Components\Contacts\Contact();
                 $contact->addEmail($email);
                 $contact->addList($list_id);
                 $contact->first_name = $firstname;
                 $returnContact = $cc->addContact($CC_ACCESS_TOKEN, $contact, true);
                 # success!
                 echo json_encode(array("status" => "success"));
             } else {
                 echo json_encode(array("status" => "error", "type" => "Email address already exists."));
             }
         } catch (CtctException $ex) {
             echo json_encode(array("status" => "error", "type" => "Looks like something went wrong. Please try again later."));
             errorlog("constantcontact", $ex->getErrors());
         }
     } else {
         echo json_encode(array("status" => "error", "type" => "Invalid list ID or email."));
         errorlog("constantcontact", $ex->getErrors());
     }
 } catch (Ctct\Exceptions\CtctException $ex) {
     foreach ($ex->getErrors() as $error) {
     }
 }
 if ($api_action == 'add') {
     /*
      * 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
      */
     if ($contactform_obj->cfg['debug']) {
         echo 'ADD CONTACT' . "\r\n";
         echo 'Contact data to send' . "\r\n";
         print_r($cc_contact);
     }
     $returnContact = $cc->addContact($cfg[$service_id]['accesstoken'], $cc_contact, true);
     if ($contactform_obj->cfg['debug']) {
         echo 'Server:' . "\r\n";
         print_r($returnContact);
     }
 } else {
     /*
      * 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
      */
     if ($list_v['updateexistingcontact']) {
         /**
          * To prevent potential json.field.lists.value.invalid errors if a list id returned in the contact search results does not exist