Using Constant Contact API: Adding an email address to constant contact list

Participant

Using Constant Contact API: Adding an email address to constant contact list

Below is my code found within header.php.  When a user fills out their email address and clicks submit, the new email address is supposed to be added to my constant contact list which is ID# 1.  I changed the settings in ctctWrapper.php with my API key as well as my user name and password, but it still isn't working. The new email addresses are not being added. Am I doing anything wrong with the code below? Please assist.  Thank you.

 

<?php

// Include the header at the top
include_once('ctctWrapper.php');


function add_cc_user()
{
// Connect to the Contacts URI
$data = new ContactsCollection();

// Create a new Contact Object
$contact = new Contact();

// This Contact's email address is...
$contact->setEmailAddress($_POST["email_address"]);

// This Contact will belong to this list - Replace where {username} is with your username
// Also remember to set listID to list number such as 1, which is typically your general interest
$contact->setLists("http://api.constantcontact.com/ws/customers/imcconstantcontact/lists/1");

// create the contact with the paremeters of the previous information
$contacts = $data->createContact($contact);

// You can print the data to see if there is an error anywhere in your submission
// will print out a 400 if there is an error and a 200 if it is successful
// print_r($contacts);

// will print out your XML that will be submitted.  Only the entry's you provide will be listed
// print_r($contact);
}
?>



<div class="constant-contact">  

<form id="constant-contact-form" action="" method="post">
<input type="text" class="rounded" height="5" size="30" maxlength="30" name="email_address" value="join our mailing list" />
<input class="rounded" size="10" type="submit" value="Submit" />
</form>

<?php
if(isset($_POST["email_address"])) {
      add_cc_user();
    }
?>


1 REPLY 1
Employee

Hey Nick,

 

I am not sure which version of the wrapper that you are using.  I believe that you may be using a third party wrapper which I am unfamiliar with.  You can download our wrapper from the code samples page which works a bit different.  Considering I have never used that wrapper I am not sur ewhich things are going on, but if your willing to switch to ours than we can do our best to help you.

Ryan Davis
Quality Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page