<h2>Add Contact Form Example</h2> <?php session_start(); include_once '../ConstantContact.php'; $username = '******'; $apiKey = 'APIKEY'; $consumerSecret = 'CONSUMERSECRET'; $Datastore = new CTCTDataStore(); $DatastoreUser = $Datastore->lookupUser($username); if ($DatastoreUser) { $ConstantContact = new ConstantContact('oauth', $apiKey, $DatastoreUser['username'], $consumerSecret); $ContactLists = $ConstantContact->getLists(); ?> <form name="addContact" action="" method="post"> 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();
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(); } else { if ($_SESSION['constantaction'] == 'Set Campaign') { $myCampaign = new Campaign(); $VerifiedEmailAddresses = $ConstantContact->getVerifiedAddresses(); /* $temp = '<html> <body> Hi test mail </body> </html>';*/ // Decode the email content and store it back into emailContent $myCampaign->name = 'Test Campaign1'; $myCampaign->subject = 'Test subject Campaign';
function constantcontact_getList($appkey, $appusername, $apptoken) { $allLists = null; try { if (!class_exists("ConstantContact")) { require_once 'CTCT-OAuth2/ConstantContact.php'; } if (!$apptoken || $apptoken == "") { return null; } $ConstantContact = new ConstantContact("oauth2", $apikey, $appusername, $apptoken); $allLists = $ConstantContact->getLists(); return $allLists['lists']; } catch (Exception $e) { $allLists = null; } return $allLists; }
include_once 'ConstantContact.php'; // Include the config.php file which contains your Api-key, consumer secret and // username include_once 'config.php'; $Datastore = new CTCTDataStore(); // $username is written to the config.php file which was entered on the // index.php $DatastoreUser = $Datastore->lookupUser($username); // if the user is found then display data else give them a chance to verify // authentication if ($DatastoreUser) { // Istantiate ConstantContact Object and push in credentails for // authentication that would be retrieved form config.php $ConstantContact = new ConstantContact('oauth', $apiKey, $username, $consumerSecret); // Get all lists from account $Lists = $ConstantContact->getLists(); // Get all verified email addresses $VerifiedEmailAddresses = $ConstantContact->getVerifiedAddresses(); // parse states and countries $allStates = $ConstantContact->getStates(); $allCountries = $ConstantContact->getCountries(); // Check to see if this is a campaign that we are editing or if this is // adding a campaign if (!empty($_GET["campaignID"]) && empty($_GET["status"])) { // Return the campaign details by ID $CampaignResult = $ConstantContact->getCampaignByID($_GET["campaignID"]); } // If user is adding a new campaign, campaignName would be set to the POST if (isset($_POST["campaignName"])) { try { // Build Campaign Object