Email Address: <input type="text" name="email_address"><br />
    First Name: <input type="text" name="first_name"><br />
    Last Name: <input type="text" name="last_name"><br />
    <h4>Contact Lists</h4>
    <div style="border: 1px #000 solid; overflow: auto; width: 400px; height: 400px;">
    <?php 
    foreach ($ContactLists['lists'] as $list) {
        echo '<input type="checkbox" name="lists[]" value="' . $list->id . '"> ' . $list->name . '<br />';
    }
    ?>
    </div>
    <input type="submit" name="submit" value="Add Contact"><br />
</form>

<?php 
    if (isset($_POST['email_address'])) {
        $Contact = new Contact();
        $Contact->emailAddress = $_POST['email_address'];
        $Contact->firstName = $_POST['first_name'];
        $Contact->lastName = $_POST['last_name'];
        $Contact->lists = $_POST['lists'];
        $NewContact = $ConstantContact->addContact($Contact);
        if ($NewContact) {
            echo "Contact Added. This is your newly created contact's information<br /><pre>";
            print_r($NewContact);
            echo "</pre>";
        }
    }
} else {
    echo ' Click <a href="example_verification.php?apiKey=' . $apiKey . '&secret=' . $consumerSecret . '&return=' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '">here</a> to authorize';
}
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;
}
     die("Logged Out, <a href='index.php'>Click Here</a> to continue.");
 } else {
     if ($_POST['SearchEmail'] == 'Search Email') {
         //Otherwise search the email address associated with this action.
         $search = $ConstantContact->searchContactsByEmail($_POST["searchEmailAddress"]);
     } else {
         if ($_POST['AddEmail'] == 'Add Email') {
             //Otherwise search the email address associated with this action.
             $userinfo = array();
             $userinfo['emailAddress'] = $_POST["searchEmailAddress"];
             $userinfo['firstName'] = $_POST["firstName"];
             $userinfo['lastName'] = $_POST["lastName"];
             $userinfo['lists'] = array('http://api.constantcontact.com/ws/customers/armiaconstantcontact/lists/1');
             $objUserinfo = new Contact($userinfo);
             //  print_r($objUserinfo);exit;
             $addEmial = $ConstantContact->addContact($objUserinfo);
             print_r($addEmial);
         } else {
             if ($_POST['GetList'] == 'Get List') {
                 $Lists = $ConstantContact->getLists();
                 print_r($Lists);
             } else {
                 if ($_POST['GetEmailList'] == 'Get Email List') {
                     $VerifiedEmailAddresses = $ConstantContact->getVerifiedAddresses();
                     print_r($VerifiedEmailAddresses);
                 } else {
                     if ($_POST['SetCampaign'] == 'Set Campaign') {
                         $myCampaign = new Campaign();
                         $temp = '<html>
                                         <body>
                                         Hi test mail
 // print_r($_POST);exit;
 $action = true;
 if ($_SESSION['constantaction'] == 'Search Email') {
     //Otherwise search the email address associated with this action.
     $email = $constantparam['email'];
     $_SESSION['constantresult'] = $ConstantContact->searchContactsByEmail($email);
 } else {
     if ($_SESSION['constantaction'] == 'Add Email') {
         //Otherwise search the email address associated with this action.
         $email = $constantparam['emailAddress'];
         if ($email != "") {
             $chkEmailexist = $ConstantContact->searchContactsByEmail($email);
             if ($chkEmailexist == "") {
                 $objUserinfo = new Contact($constantparam);
                 // print_r($objUserinfo);exit;
                 $addEmailReturn = $ConstantContact->addContact($objUserinfo);
                 if ($addEmailReturn) {
                     $_SESSION['constantresult'] = "Email subscribed sucessfully!";
                 }
             } else {
                 $_SESSION['constantresult'] = "Email subscribed failed!";
             }
         } else {
             $_SESSION['constantresult'] = "Email subscribed failed!";
         }
     } else {
         if ($_SESSION['constantaction'] == 'Get List') {
             $_SESSION['constantresult'] = $ConstantContact->getLists();
         } else {
             if ($_SESSION['constantaction'] == 'Get Email List') {
                 $_SESSION['constantresult'] = $ConstantContact->getVerifiedAddresses();