cannot opt-back in

Highlighted
Occasional Participant

cannot opt-back in

I have a test contact that I put in do not mail.  I am trying to write the code to let them opt in again.  I cannot figure this out.


the docs say to get all the details and append the new lists to the contact and then do an add.  Edit contact doesnt have that option to add contact lists.


can I not just subscribe them back to a list and it work?

7 REPLIES 7
Highlighted
CTCT Employee

Re: cannot opt-back in

You can find details on opting in a subscriber who has opted out here. Basically this involves updating that contact to include the contact list you wish for them to be a part of. Also, the <OptInSource> for the contact MUST be "ACTION_BY_CONTACT" in order to indicate that the contact is the one taking the action to be opted back in.


 


I would be happy to help resolve this if you are having difficulties doing this, but would need some more details regarding what you are doing as well as the XML you are using to update the contact to opt them back in. 

 

David J

Highlighted
Occasional Participant

could you supply some sample

could you supply some sample php code for doing this?  I am lost.  Your sample update contact code does not show code for updating the lists.  I was under the assumption that you had to add subscriptions after the contact was created.


 


Thanks,


 

Highlighted
CTCT Employee

Re: could you supply some sample

I'd be happy to provide some sample code for this. Are you using the PHP Library or the PHP Sample Forms? This can be done with either sample, but if you are using the sample forms (not the PHP Library), the code to opt back in a contact would be the following:

 

<?php

//Instantiate Contact class
include_once('cc_class.php');
$ccContactOBJ = new CC_Contact();

//Retrieve current details for provided email address
$details = $ccContactOBJ->getSubscriberDetails('test@example.com');

//Set the contact list you would like the previously unsubscribed contact to be a part of
$details['lists'] = array('http://api.constantcontact.com/ws/customers/{username}/lists/{list-id}');

//Create XML representing the contact details
$contactXml = $ccContactOBJ->createContactXML($details['id'], $details);

// Send the HTTP Put to update this contact's information and opt them back into your list
$editResponse = $ccContactOBJ->editSubscriber($details['id'], $contactXml); 

?>

 

If you are using the PHP library, let me know and I'll be happy to write up an example using that as well. If you have any questions please let me know.

David J

Highlighted
Occasional Visitor

Re: could you supply some sample

The code you have given seems to have some issues as you define $response twice in a row.

 

I am trying to do the same thing that is "opt in" after a user has been removed and they have had their status changed to "Do not mail".

 

I cannot get your example to work.  Would you please provide a working example?  Thank you!

 

Ben LeDuc

bpleduc@hotmail.com

Highlighted
CTCT Employee

Re: could you supply some sample

Hi Ben,

 

I certainly apologize for the code I posted earlier. I have no idea how that happened but this is clearly my mistake, as that code would not work at all.

 

I have edited my previous post with code that should work correctly for updating your contact. I apologize for any inconvenience that this issue has caused. Please let me know if you have any questions or concerns regarding this.

David J

Highlighted
Occasional Visitor

Re: could you supply some sample

Thanks for the edit to the code.

 

I'm having an issue w/ the getSubscriberDetails code as it does not return the expected results.  Please see my code below:

 

 

if($_POST["subscribeEmail"] != "") {
  $ccContactOBJ = new CC_Contact();
  if( !$ccContactOBJ->subscriberExists($_POST["subscribeEmail"]) ) {
  echo "<h4>Exists.</h4>";
  //Retrieve current details for provided email address
  $details = $ccContactOBJ->getSubscriberDetails($_POST["subscribeEmail"]);
 print_r($details);

 

 

The print_r above returns:

Array ( [id] => [email_address] => [first_name] => [last_name] => [middle_name] => [company_name] => [job_title] => [home_number] => [work_number] => [address_line_1] => [address_line_2] => [address_line_3] => [city_name] => [state_code] => [state_name] => [country_code] => [zip_code] => [sub_zip_code] => [custom_field_1] => [custom_field_2] => [custom_field_3] => [custom_field_4] => [custom_field_5] => [custom_field_6] => [custom_field_7] => [custom_field_8] => [custom_field_9] => [custom_field_10] => [custom_field_11] => [custom_field_12] => [custom_field_13] => [custom_field_14] => [custom_field_15] => [notes] => [mail_type] => [status] => [lists] => Array ( ) )

 

 

I have tried this for emails that are Active and Do Not Mail.

 

Please let me know what might be wrong.  The subscriberExists function works correctly in identifiying the email.

 

Maybe I have the wrong CC_Contact class?  Would you send me a link to the correct one?

 

Thanks!

 

Ben LeDuc

bpleduc@hotmail.com

Highlighted
CTCT Employee

Re: could you supply some sample

Without being able to see where your if statement ends, it sounds like you are performing the CC_Contact->getSubscriberDetails() function on an email address that does not exist, so you are seeing an empty set of properties for the returned Contact object. I believe that this is because you are testing to see if the subscriber does NOT exist ( if(!$ccContactOBJ->subscriberExists($_POST["subscribeEmail"]) )) , then pulling details for that email address.

 

If you were to use the code below, I believe that this will resolve your issue.

 

if($_POST["subscribeEmail"] != "") {
    $ccContactOBJ = new CC_Contact();
    if($ccContactOBJ->subscriberExists($_POST["subscribeEmail"]))
    {
        echo "<h4>Exists.</h4>";
        //Retrieve current details for provided email address
        $details = $ccContactOBJ->getSubscriberDetails($_POST["subscribeEmail"]);
    }
    print_r($details);
}

David J

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured