Here's a sample script to create a new contact. It's assuming you have a member signup form on your page that has collected first name, last name, email address, and zip code.
This is based on the "SAMPLE: PUT (Update) a Contact (PHP)" script found here:
http://developer.constantcontact.com/samples/putSubscriber
------------------------------------
<?php
$first_name = trim($_POST);
$last_name = trim($_POST);
$email = trim($_POST);
$zipcode = $_POST;
/////////// REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////
$UN = "your_member_name_here";
$PW = "your_password_here";
$Key = "your_API_key_here";
$entry = '<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>' . date('c') . '</updated>
<author></author>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>' . $email . '</EmailAddress>
<FirstName>' . $first_name . '</FirstName>
<LastName>' . $last_name . '</LastName>
<PostalCode>' . $zipcode . '</PostalCode>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/' . $UN . '/lists/1" />' // Do this for all the lists you want to add to
. '<ContactList id="http://api.constantcontact.com/ws/customers/' . $UN . '/lists/2" />' // Be sure to get the correct list number(s) for your list(s)
. '</ContactLists>
</Contact>
</content>
</entry>';
// Initialize the cURL session
$request ="http://api.constantcontact.com/ws/customers/" . $UN . "/contacts";
$session = curl_init($request);
// Set up digest authentication
$userNamePassword = $Key . '%' . $UN . ':' . $PW ;
// Set cURL options
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS , $entry);
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session, CURLOPT_HEADER, false); // Do not return headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); // If you set this to 0, it will take you to a page with the http response
// Execute cURL session and close it
$response = curl_exec($session);
curl_close($session);
////////////////// END REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////////
// Your code goes here: typically sending a confirmation email, and/or a Header("Location: your_page.php") redirect
?>
... View more