コード例 #1
0
		<input type="text" name="searchEmailAddress" maxlength="50">
		<input type="submit" name="submit" value="Submit" />
	</form>
	<!-- The HTML code from here to the end is Preformatted so that the information returned by the API is readable.-->
	<pre>
	
<?php 
    // Check to make sure that we have a search result. Is $search == false then we did not find any contacts.
    if ($search != false) {
        if ($_POST["action"] == "delete") {
            // If the user clicked on the Unsubscribe Contact button then we will want to unsubscribe them.
            $ConstantContact->DeleteContact($search[0]);
        } else {
            // the only action left is a basic search, so we will get the Contact details and display them.
            //First we will get the Contact Details from the Wrapper.
            $details = $ConstantContact->getContactDetails($search[0]);
            //Then we will let the user know that a contact exists with that email address
            echo $details->emailAddress . " Exists";
            ?>

<!-- Create a button allowing the user to unsubscribe the contact. This button is functional. DO NOT use it unless you have access to the email address being unsubscribed. -->
<form action="index.php" method="post">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="searchEmailAddress" value="<?php 
            echo $details->emailAddress;
            ?>
" />
<input type="submit" name="submit" value="Unsubscribe Contact" />
</form>

<?php 
コード例 #2
0
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;
}