I have a windows hosting server which my client hosts her php based website on.
I am trying to use the below code to insert a contact into the constant contact account.
The windows server does have curl installed
when I check if curl is installed
via doing a var_dump(curl_version());
I get the below which shows me curl is installed
array(9) { ["version_number"]=> int(464128) ["age"]=> int(3) ["features"]=> int(2716) ["ssl_version_number"]=> int(0) ["version"]=> string(6) "7.21.0" ["host"]=> string(13) "i386-pc-win32" ["ssl_version"]=> string(14) "OpenSSL/0.9.8q" ["libz_version"]=> string(5) "1.2.3" ["protocols"]=> array(16) { [0]=> string(4) "dict" [1]=> string(4) "file" [2]=> string(3) "ftp" [3]=> string(4) "ftps" [4]=> string(4) "http" [5]=> string(5) "https" [6]=> string(4) "imap" [7]=> string(5) "imaps" [8]=> string(4) "ldap" [9]=> string(4) "pop3" [10]=> string(5) "pop3s" [11]=> string(4) "rtsp" [12]=> string(4) "smtp" [13]=> string(5) "smtps" [14]=> string(6) "telnet" [15]=> string(4) "tftp" } }
The php code I am using which I know works on a LAMP server but can not figure out why its not working on my windows server with php installed is
// Instantiate CC_Contact class
$date = date("Y-m-d\TH:i:s");
/////////// REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////
$UN = "******";
$PW = "******";
$Key = "******";
$entry = $theXml = <<<THE__XML
<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"></title>
<updated>$date</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>$emailaddr</EmailAddress>
<FirstName>$firstname</FirstName>
<LastName>$lastname</LastName>
<CustomField6>$cname</CustomField6>
<CustomField1>$info</CustomField1>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/********/lists/**" />
</ContactLists>
</Contact>
</content>
</entry>
THE__XML;
// Initialize the cURL session
$request ="https://api.constantcontact.com/ws/customers/*******/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, 0); // 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 adding contact to constant contact
I am hoping someone will have a suggestion for me. Again I know php is working because I have a website written in php that works fine thanks
Hello Jason,
I have reviewed your code and it appears that the most likely source of your problem is this code :
<id>data:,none</id> which should be <id>data:,none</id>.
An additional step to look into is this is not to case is to try adding this CURL option:
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
If adding that as a CURL option is the resolution to your issue then you are likely having an issue becuase your server has outdated SSL certificates and is unable to verify the certificate for https://api.constantcontact.com.
If you continue to experience an error it would be a great help to have the error message or more detail about the error itself.
Hello
Thanks now I copy and pasted that id line to replace what I had and I get the below error
Error 400: The request contains errors in the common Atom sections, which lie outside or , such as , , or .
Hello Chris,
It appears the issue with the <id>data:,none</id> is that the forum software is convering the colon into the HTML entity code for a colon. I have done a bit more work with the XML and after changing the : back to a normal colon your XML should work.
If it does not you may want to try changing <ContactList id="http://api.constantcontact.com/ws/customers/********/lists/**" /> to <ContactList id="http://api.constantcontact.com/ws/customers/********/lists/**" ></ContactList>
Sincerely,
Elijah G.
Tier 2 Support