Exemple #1
0
         if (isset($value->name) && $value->name == $list_name) {
             $list_id = $value->id;
         }
     }
 }
 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());
 }