I'm using the PHP example code to integrate Constant Contact with a web site I'm working on. I'm testing my code now. When an existing subscriber tries to subscribe again, my code get's the information on file for them from CC, creates a new contactxml and then calls editSubscriber to make sure they're in the right list and to have cc send out the confirmation email again. Here's my code:
$ccParams = array("firstName" => $fullDetails, "lastName" => $fullDetails, "emailAddress" => $fullDetails, "status" => $status, "mailType" => $mailType, "lists" => $lists);
$contact = $cc->createContactXML($id, $ccParams);
$result = $cc->editSubscriber($id, $contact);
if($result) {
echo "<p>Almost done! Your email address was in our system, but our records indicate you did not confirm your subscription when we sent you the confirmation email. Another one was sent to your email address. Please click the link in the email to confirm you want to join our mailing list. If you don't click the link, you won't be added to the list.</p>\n";
}
else {
echo "<p class='warning'>Oops, this is embarassing 2. I encountered an error while trying to add you to our newsletter mailing list. You can <a href='/path/to/myscript'>try again</a> if you'd like or <a href='mailto:webmaster@mydomain.com'>shoot the webmaster an email</a> so you can be manually added to the list. Sorry for the inconvenience.</p>\n";
}
I narrowed the problem down to the editSubscriber function. It calls doServerCall to perform the update, and the return value from doServerCall is "1". editSubscriber generates an error if the return value from doServerCall is not empty, so the 1 makes it think there's an error. Funny thing is I'm getting the confirmation email, so I suspect the check of the return value from doServerCall is wrong. It should probably be checking it as a boolean instead of checking to see if it's empty, but I'm not sure of that. Here's the editSubscriber function:
public function editSubscriber($contactUrl, $contactXML) {
$return = $this->doServerCall($contactUrl, $contactXML, 'PUT');
if (!empty($return)) {
echo "<h1>\$return == $return</h1>\n";
if (strpos($return, '<') !== false) {
$parsedReturn = simplexml_load_string($return);
if (!empty($parsedReturn->message)) {
$this->lastError = $parsedReturn->message;
}
} else {
$this->lastError = $parsedReturn->message;
}
echo "<p>Returning false</p>\n";
return false;
}
echo "<p>Returning true</p>\n";
return true;
}
I added a couple of debugging statements. Any idea why doServerCall would return 1 instead of an empty string? Should I change editSubscriber to test the return value as a boolean? Any help is appreciated.
Thanks,
Troy