The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

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

Highlighted
Regular Visitor

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
Highlighted
Employee

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

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

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured