Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "Scripts/ConstantContact/src/Ctct/autoload.php";
- use CtctConstantContact;
- use CtctComponentsContactsContact;
- use CtctComponentsContactsContactList;
- use CtctComponentsContactsEmailAddress;
- use CtctExceptionsCtctException;
- define("APIKEY", "*** Censored Media (18+ only) ***");
- define("ACCESS_TOKEN", "*** Censored Media (18+ only) ***");
- $cc = new ConstantContact(APIKEY);
- // attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
- $lists = $cc->getLists(ACCESS_TOKEN);
- $action = "Getting Contact By Email Address";
- $Email = "asdf@asdf.com";
- $FirstName = "Asdf";
- $LastName = "Ghjk";
- // check to see if a contact with the email addess already exists in the account
- $response = $cc->getContactByEmail(ACCESS_TOKEN, $Email);
- // create a new contact if one does not exist
- if (empty($response->results)) {
- $action = "Creating Contact";
- $contact = new Contact();
- $contact->addEmail($Email);
- $contact->addList('1');
- $contact->first_name = $FirstName;
- $contact->last_name = $LastName;
- $returnContact = $cc->addContact(ACCESS_TOKEN, $contact);
- // update the existing contact if address already existed
- } else {
- $action = "Updating Contact";
- $contact = $response->results[0];
- $contact->addList('1');
- $contact->first_name = $FirstName;
- $contact->last_name = $LastName;
- $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact);
- }
- // catch any exceptions thrown during the process and print the errors to screen
- if (isset($returnContact)) {
- echo '<div class="container alert-success"><pre class="success-pre">';
- print_r($returnContact);
- echo '</pre></div>';
- }
- print '<p>'.$action.'</p>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement