I found this bit of code online, and it works fine for addinga contact to my list. However, there are a couple of things I need this to do: 1) If the contact exists in the Do Not Mail or Removed categories, I need to be able to add them back. 2) How can I modify this to alo insert additional fields? (name, zip, custom1, etc) Any help is appreciated. ------------------------------------------ The code on my insert page: ------------------------------------------ $myKey = '######'; $myUn = '######'; $myPW = '######'; $addToCC = $_POST['addToCC']; if($addToCC == 1) { #add user to mailing list $cc = new ConstantContact( $myKey, $myUN, $myPW ); $result = $cc->addContactToMailingList($email, "https://api.constantcontact.com/ws/customers/######/lists/10"); } ---------------------------------- The PHP class: ---------------------------------- class ConstantContact{ private $api_key; private $user_name; private $user_pass; private $auth_pass; public function __construct($apikey, $username, $userpassword){ $this->api_key = $api_key; $this->user_name = $username; $this->user_password = $userpassword; $this->auth_pass = $apikey . "%" . $username . ":" . $userpassword; } public function __destruct(){ } public function addContactToMailingList($emailAddressOfUser, $contactList){ $contactURL = "https://api.constantcontact.com/ws/customers/{$this->user_name}/contacts"; $contactListToAddTo = $contactList; $update_date = date("Y-m-d").'T'.date("H:i:s").'+01:00'; $rawEntry = "<entry xmlns='http://www.w3.org/2005/Atom'></entry>"; $xml_object = simplexml_load_string($rawEntry); $title_node = $xml_object->addChild("title", htmlspecialchars("TitleNode")); $updated_node = $xml_object->addChild("updated", htmlspecialchars($update_date)); $author_node = $xml_object->addChild("author"); $author_name = $author_node->addChild("name", htmlspecialchars($this->user_name)); $id_node = $xml_object->addChild("id", "data:,none"); $summary_node = $xml_object->addChild("summary", htmlspecialchars("Customer document")); $summary_node->addAttribute("type", "text"); $content_node = $xml_object->addChild("content"); $content_node->addAttribute("type", "application/vnd.ctct+xml"); $contact_node = $content_node->addChild("Contact", htmlspecialchars("Customer document")); $contact_node->addAttribute("xmlns", "http://ws.constantcontact.com/ns/1.0/"); $email_node = $contact_node->addChild("EmailAddress", urldecode(htmlspecialchars($emailAddressOfUser))); $optin_node = $contact_node->addChild("OptInSource", htmlspecialchars('ACTION_BY_CUSTOMER')); $contactlists_node = $contact_node->addChild("ContactLists"); $contactlist_node = $contactlists_node->addChild("ContactList"); $contactlist_node->addAttribute("id", urldecode(htmlspecialchars($contactListToAddTo))); $entry = $xml_object->asXML(); $curl_conn = curl_init($contactURL); // Set up Basic authentication - username and password. curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl_conn, CURLOPT_USERPWD, $this->auth_pass); curl_setopt($curl_conn, CURLOPT_FOLLOWLOCATION ,1); curl_setopt($curl_conn, CURLOPT_POST, 1); curl_setopt($curl_conn, CURLOPT_POSTFIELDS , $entry); curl_setopt($curl_conn, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml")); curl_setopt($curl_conn, CURLOPT_HEADER, 0); // Do not return headers curl_setopt($curl_conn, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curl_conn, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($curl_conn); curl_close($curl_conn); echo $response; //return true; } }
... View more