Created
November 20, 2009 13:28
-
-
Save drscott173/239500 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function save_contact($first, $last, $email, $phone, $zip) { | |
| $UN = "<username of your constant contact account, not the developer account>"; | |
| $PW = "<password to the username in $UN>"; | |
| $Key = "<your developer API key, not the secret key>"; | |
| $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><![CDATA[' . $email . ']]></EmailAddress> | |
| <FirstName>' . $first . '</FirstName> | |
| <LastName>' . $last . '</LastName> | |
| <PostalCode>' . $zip . '</PostalCode> | |
| <OptInSource>ACTION_BY_CUSTOMER</OptInSource> | |
| <ContactLists> | |
| <ContactList id="https://api.constantcontact.com/ws/customers/' . $UN . '/lists/1" /> | |
| </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); | |
| curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0); | |
| // Execute cURL session and close it | |
| $response = curl_exec($session); | |
| curl_close($session); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment