function constantcontact_addContact($info, $list, $appkey, $appusername, $apptoken) { if (!$apptoken || $apptoken == "") { return null; } if (!class_exists("ConstantContact")) { require_once 'CTCT-OAuth2/ConstantContact.php'; } try { $ConstantContact = new ConstantContact("oauth2", $apikey, $appusername, $apptoken); $search = $ConstantContact->searchContactsByEmail($info["email"]); if ($search && isset($search[0])) { $details = $ConstantContact->getContactDetails($search[0]); if (isset($details->lists)) { $list_added = false; foreach ($details->lists as $l) { if ($l == $list) { $list_added = true; } } if (!$list_added) { $list_array = $details->lists; array_push($list_array, $list); $details->lists = $list_array; $details->status = "Active"; $ConstantContact->updateContact($details); return true; } return true; } } } catch (Exception $e) { return false; } $postFields = array(); $postFields["emailAddress"] = $info["email"]; $postFields["firstName"] = $info["first_name"]; $postFields["lastName"] = $info["last_name"]; $postFields["optInSource"] = "ACTION_BY_CONTACT"; $postFields["lists"] = array($list); try { $ConstantContact = new ConstantContact("oauth2", $apikey, $appusername, $apptoken); $newContact = new Contact($postFields); $result = $ConstantContact->addContact($newContact); return true; } catch (Exception $e) { return false; } return false; }