<?php
//Constant Contact//
$emailaddress = trim("email");
/////////// REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////
$UN = "un";
$PW = "pw";
$Key = "api";
$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>' . $emailaddress . '</EmailAddress>
<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
. '
</ContactLists>
</Contact>
</content>
</entry>';
// Initialize the cURL session
$request ="https://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_BASIC);
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);
?>
No comments:
Post a Comment