The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Server Migration results in eNews signup failure

Highlighted
Developer

Server Migration results in eNews signup failure

Hi,

 

I've got a problem I'm hoping someone can help me with. Two weeks ago, my web site with a customized Constant Contact sign up form was migrated to a new server. Both the old server and the new server are Linux. But the enews sign-up now fails.

 

The code is the same, so I am assuming this is a server setting that could be easily tweaked if I had the slightest idea where to look for it. I read in another thread that it might a curl setting, also. Any thoughts would be most appreciated!  This is the form that is failing: http://www.wmf.org/e-newsletter

Instead of getting a 'thank you' message and the contact being inserted into the Constant Contact list, I get a Page Could Not Be Found 500 error on the client side (Drupal error log) and on the server side, they are seeing a rather generic error message: Premature end of script headers: index.php, referer: http://www.wmf.org/e-newsletter

 

Many thanks in advance for helping me out here!

 

Best,

Lissa

21 REPLIES 21
Highlighted
Employee

Re: Server Migration results in eNews signup failure

Hey Lisa,

 

In order for me to be able to see what could be causing the error I would need to see the code in order to troubleshoot it.  Please provide it on the forum or in a private message.

 

 

Ryan Davis
Quality Engineer
Highlighted
Developer

Re: Server Migration results in eNews signup failure

Hey Ryan,

 

Thanks for your reply. I need to amend my initial statement. The contact's email address actually IS inserting into the Constant Contact list; so the only problem is that the "Thank you" page after signing up is not being returned. It is the same page that should refresh with the message: Thank you for signing up for our newsletter. You should receive a confirmation email shortly.,

 

The code for doing that, below,  worked fine on the old server, but is not working on the new.  Instead it is returning a 500 /Page Not Found error.

 

 

<?php

function newsletter_menu(){
    $items['e-newsletter/thank-you'] = array(
        'title' => t("Thank You"),
        'page callback' => "newsletter_thankyou_page",
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );   
    $items['e-newsletter'] = array(
        'title' => t("E-Newsletter"),
        'page callback' => "newsletter_signup_page",
        'access arguments' => array('access content'),
                'type' => MENU_CALLBACK,
    );
    $items['admin/settings/newsletter'] = array(
        'title' => 'Constant Contact Email List Settings',
        'description' => 'Configure the Constant Contact and email  list settings',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('newsletter_admin'),
        'access arguments' => array('administer newsletter'),
        'type' => MENU_NORMAL_ITEM,
    );
    $items['e-newsletter/tests'] = array(
        'title' => 'Constant Contact Email Tests',
        'page callback' => 'newsletter_tests',
        'page arguments' => array('newsletter_admin'),
        'access arguments' => array('administer newsletter'),
        'type' => MENU_CALLBACK,
    );   
    return $items;
}


function newsletter_theme(){
    return array(
            'newsletter_signup' => array(
            'arguments' => array('form' => NULL),
            'template' => 'theme/newsletter_signup'
        ),
            'newsletter_thankyou' => array(
            'arguments' => array('form' => NULL),
            'template' => 'theme/newsletter_thankyou'
        ),
            'test_results' => array(
            'arguments' => array('form' => NULL),
            'template' => 'theme/test_results'
        )       
    );
}

function newsletter_thankyou_page(){
    return theme('newsletter_thankyou');   
}

function newsletter_tests(){
    return theme('test_results');
}


function newsletter_signup_page(){
    if(!variable_get("cc_toggle_newsletter", 1)){
        return drupal_goto("contact/request-enews/");
    }
    require_once("sites/all/modules/custom/constantcontact/wmfcc.php");
    if(user_is_logged_in()){
        $cc = get_constant_contact();
        global $user;
        $email = $user->mail;
        $status = get_reg_status_from_cc($cc, urlencode($email));
       
        if($status['newsletter']){
            //$form = '<h2 class="title">You are signed up for the WMF e-newsletter.</h2><br/><p>You can unsubscribe by editing your profile, or by clicking unsubscribe from any e-newsletter you have received.</p>';
            $form = variable_get('cc_enews_already_signed_up_text',"");
            return theme('newsletter_signup', $form);
        }
    }
   
    $enews_headline_text = variable_get('cc_enews_headline_text',"");
   
    $form = t("<h2 class='title'>$enews_headline_text</h2>");
    $form .= drupal_get_form('newsletter_form');
    return theme('newsletter_signup', $form);
}

function newsletter_form(){

    $form['firstname'] = array(
     '#type' => 'textfield',
     '#title' => 'First Name',
        '#required' => true
    );
    $form['lastname'] = array(
     '#type' => 'textfield',
     '#title' => 'Last Name',
     '#required' => true
    );
    $form['email'] = array(
     '#type' => 'textfield',
     '#title' => 'Email',
     '#required' => true
    );
    $form['emailconf'] = array(
     '#type' => 'textfield',
     '#title' => 'Confirm Email',
     '#required' => true
    );
    $form['campaign'] = array(
     '#type' => 'checkbox',
     '#title' => variable_get('cc_enews_additional_signup_text',"") //'Also sign me up for emails about Special Campaigns and Announcements'
     );
     $form['submit'] = array(
     '#type' => 'submit',
     '#value' => 'Submit'
     );
     
     return $form;
}

function newsletter_form_validate($form, &$form_state){
    if($form_state['values']['email']
    != $form_state['values']['emailconf']){
        form_set_error('email', t('Your email addresses must match.'));
    }
}

function newsletter_form_submit($form, &$form_state){

    require_once("sites/all/modules/custom/constantcontact/wmfcc.php");

    $cc = get_constant_contact();

    //print_r($form_state);
    $newsletter_uri = variable_get('cc_newsletter_list_uri',"");
    $lists = array($newsletter_uri);
    if($form_state['values']['campaign'] == 1){
        $emaillist_uri = variable_get('cc_email_list_uri',"");
        $lists[] = $emaillist_uri;       
    }

    $email = urlencode($form_state['values']['email']);
    //$status = get_reg_status_from_cc($cc, $email);
    //$overview = get_contact_overview_xml($cc, $email);
    //$id = get_user_id_from_contact_overview($overview);
   
    $response = add_user_or_create_and_add_to_cc_list($cc,
            $form_state['values']['firstname'],
            $form_state['values']['lastname'],
            $email,
            $lists);

    if($response == FALSE){
        drupal_set_message("The email service is currently offline so we could not update your status.  Please try again later or email us for your status.");
    } else {
        drupal_goto('e-newsletter/thank-you');
    }

}

function newsletter_perm(){
    return array('administer newsletter');
}

function newsletter_admin() {
    $form = array();
    $form['cc_toggle_newsletter'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Constant Contact'),
    '#default_value' => variable_get('cc_toggle_newsletter', TRUE),
    '#description' => t("Use Constant Contact."),
    );

    $form['cc_user_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Constant Contact User Name'),
    '#default_value' => variable_get('cc_user_name',""),
    '#size' => 60,
    '#maxlength' => 60,
    '#description' => t("User name for Constant Contact account."),
    '#required' => TRUE,
    );
    $form['cc_password'] = array(
    '#type' => 'textfield',
    '#title' => t('Constant Contact password'),
    '#default_value' => variable_get('cc_password',""),
    '#size' => 60,
    '#maxlength' => 60,
    '#description' => t("Password for Constant Contact account."),
    '#required' => TRUE,
    );
    $form['cc_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Constant Contact API key'),
    '#default_value' => variable_get('cc_api_key',""),
    '#size' => 60,
    '#maxlength' => 60,
    '#description' => t("API Key for Constant Contact account."),
    '#required' => TRUE,
    );
    $form['cc_newsletter_list_uri'] = array(
    '#type' => 'textfield',
    '#title' => t('Constant Contact Newsletter URI'),
    '#default_value' => variable_get('cc_newsletter_list_uri',""),
    '#size' => 100,
    '#maxlength' => 200,
    '#description' => t("URI for Constant Contact Newsletter"),
    '#required' => TRUE,
    );
    $form['cc_email_list_uri'] = array(
    '#type' => 'textfield',
    '#title' => t('Constant Contact Email URI'),
    '#default_value' => variable_get('cc_email_list_uri',""),
    '#size' => 100,
    '#maxlength' => 200,
    '#description' => t("URI for Constant Contact Email List"),
    '#required' => TRUE,
    );
   
    $form['cc_enews_headline_text'] = array(
    '#type' => 'textfield',
    '#title' => t('E-Newsletter Signup Page Headline'),
    '#default_value' => variable_get('cc_enews_headline_text',""),
    '#size' => 100,
    '#maxlength' => 200,
    '#description' => t(""),
    '#required' => TRUE,
    );
   
    $form['cc_enews_already_signed_up_text'] = array(
    '#type' => 'textarea',
    '#title' => t('E-Newsletter Signup Page - Already Signed Up For E-News Message'),
    '#default_value' => variable_get('cc_enews_already_signed_up_text',""),
    '#description' => t("Enter some text for a user to see if they are already signed up for the e-newsletter."),
    '#required' => TRUE,
    );
   
    $form['cc_enews_additional_signup_text'] = array(
    '#type' => 'textfield',
    '#title' => t('E-Newsletter Signup Page - Additional Checkbox Text'),
    '#default_value' => variable_get('cc_enews_additional_signup_text',""),
    '#size' => 100,
    '#maxlength' => 200,
    '#description' => t(""),
    '#required' => TRUE,
    );
   
    return system_settings_form($form);
}



?>

 

 

The base code is pasted below, though there are several supporting files, too:

 

<?php
/**
 * An easy to use Constant Contact PHP Interface
 *
 * @name      ConstantContact PHP Interface
 * @author    Jared De Blander <jared@iofast.com>
 * @copyright (c) 2008 Jared De Blander
 * @link      http://www.iofast.com
 * @link      http://www.jareddeblander.com
 * @license   MIT
 * @version   $Rev$
 * @internal  $Id$
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * NOTICE:
 * Further alteration of this software were made by ESI design.
 *
 */
class constant_contact{

  //Debugging state
  private $debug;

  private $user;
  private $pass;
  private $api_key;

  /**
   * The ConstantContact contructor
   *
   * @param String $user - Your username
   * @param String $pass - Your password
   * @param String $api_key - Your API Key
   */
  public function __construct($user='', $pass='', $api_key=''){
    $this->debug=false;

    $this->set_user($user);
    $this->set_pass($pass);
    $this->set_api_key($api_key);
  }
 
  /**
   * Get a contact
   * @param int $contact_id - ID of the contact
   */
 
  public function get_contact($url){
        $post = "";
         $response = $this->fetch($url, $post);
          return $response;
  }
 
  public function get_contact_from_id($id){
          $url='https://api.constantcontact.com/ws/customers/'.$this->user.'/contacts/'.$id;
        return get_contact_from_url($url);
  }
 
  public function get_contact_from_url($url){
        $post = "";
         $response = $this->fetch($url, $post);
          return $response;
  }
 
  public function update_contact($contact){
     
          $tmpfile = tmpfile();
          fwrite($tmpfile, $contact);
          fseek($tmpfile, 0);
     
            $contact_arr = $this->xml_to_array($contact);
          $url = $contact_arr['entry']['id']['value'];
        $url = str_replace('http://', 'https://', $url);
       
          $session = curl_init($url);
         
        $usrpsw = $this->api_key. '%' .$this->user .':'.$this->pass;
        curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($session, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($session, CURLOPT_USERPWD, $usrpsw);
        curl_setopt($session, CURLOPT_INFILE, $tmpfile);
        fclose($tmpfile);
       
        curl_setopt($session, CURLOPT_PUT, 1);
        curl_setopt($session, CURLOPT_INFILESIZE, strlen($contact));

        curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
        curl_setopt($session, CURLOPT_HEADER, 0);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, 0);
        $response = curl_exec($session);
   
        $this->debug_print("HTTP Response Code '".curl_getinfo($session, CURLINFO_HTTP_CODE)."'");
        $this->debug_print("Received:<pre>\n\n---START---\n". htmlspecialchars($response) ."\n---END---\n\n</pre>");
   
        curl_close($session);
        return $response;
     
  }
 
  /**
   * Add a contact
   *
   * @param String $first_name - First name
   * @param String $last_name - Last name
   * @param String $email - Email address
   * @param Array of Strings $lists - The lists to subscribe to. This should be the entire id of the list
   */
  public function add_contact($first_name, $last_name, $email, $lists){
     
    $post ='<entry xmlns="http://www.w3.org/2005/Atom">';
    $post.='<title type="text"> </title>';
    $post.='<updated>'.date('Y-m-d\TH:i:s\Z') .'Z</updated>';
    $post.='<author></author>';
    $post.='<id>data:,none</id>';
    $post.='<summary type="text">Contact</summary>';
    $post.='<content type="application/vnd.ctct+xml">';
    $post.='<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">';
    $post.='<EmailAddress>'.urldecode($email).'</EmailAddress>';
    $post.='<FirstName>'.$first_name.'</FirstName>';
    $post.='<LastName>'.$last_name.'</LastName>';
    $post.='<OptInSource>ACTION_BY_CONTACT</OptInSource>';
    $post.='<ContactLists>';
    foreach($lists as $list){
        $post.='<ContactList id="' . $list . '" />';         
    }
    $post.='</ContactLists>';
    $post.='</Contact>';
    $post.='</content>';
    $post.='</entry>';
     
    $url='https://api.constantcontact.com/ws/customers/'.$this->user.'/contacts';
    $credentials = $this->api_key. '%' .$this->user .':'.$this->pass;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERPWD,  $credentials);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS , $post);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
   
    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
  }

  /**
   * Turn debugging output off.
   *
   */
  public function debug_off(){
    $this->debug=false;
  }

  /**
   * Turn debugging output on.
   *
   */
  public function debug_on(){
    $this->debug=true;
  }
 
  public function ping(){
      $url = "https://api.constantcontact.com/ws/customers/".$this->user."/";
    $credentials=$this->api_key.'%'.$this->user.':'.$this->pass;
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERPWD,  $credentials);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POST, 0);
      curl_setopt($ch, CURLOPT_HEADER, False);
      return curl_exec($ch);
  }

  /**
   * Print debugging output
   *
   * @param String $string - String to print
   */
  private function debug_print($string){
    if($this->debug) echo "ConstantContact Debug: $string<br>\n";
  }

  /**
   * Fetch a URI from ConstantContact
   *
   * @param String $url - URL to connect to
   * @param String $post - POST data to include
   * @return Respose
   */
  private function fetch($url, $post){
    $credentials=$this->api_key.'%'.$this->user.':'.$this->pass;
    $ch=curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERPWD,  $credentials);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);   
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if(strlen(trim($post))>0){
      $this->debug_print("And Posting:<pre>\n\n---START---\n". htmlspecialchars($post) ."\n---END---\n\n</pre>");
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/atom+xml'));
    }else{
      $this->debug_print("Not posting");
      curl_setopt($ch, CURLOPT_POST, 0);
    }
    if($this->debug){
      curl_setopt($ch, CURLOPT_HEADER, True);
    }else{
      curl_setopt($ch, CURLOPT_HEADER, False);
    }

    $response = curl_exec($ch);
    $this->debug_print("HTTP Response Code '".curl_getinfo($ch, CURLINFO_HTTP_CODE)."'");
    $this->debug_print("Received:<pre>\n\n---START---\n". htmlspecialchars($response) ."\n---END---\n\n</pre>");
   
    curl_close($ch);
    return $response;
  }


  public function get_activities_xml(){
    $url='https://api.constantcontact.com/ws/customers/'.$this->user.'/activities';
    $post='';

    $response=$this->fetch($url, $post);
    return $response;
  }

  /**
   * Return your list of campaigns
   *
   * @return XML document containing your campaigns
   */
  public function get_campaigns_xml(){
    $url='https://api.constantcontact.com/ws/customers/'.$this->user.'/campaigns';
    $post='';

    $response=$this->fetch($url, $post);
    return $response;
  }

  /**
   * Return your list of contacts. Paths can be specified to show
   * information about a specific contact. Path data can be found
   * in the master contact list by specifying no path.
   *
   * @param String $path - Optionally specify a path
   * @return XML document containing your contacts.
   */
  public function get_contacts_xml($path=''){
    $url='https://api.constantcontact.com/ws/customers/'.$this->user.'/contacts'.$path;
    $post='';
    $response = $this->fetch($url, $post);
    return $response;
  }


  /**
   * Used to retrieve your list information. Paths can be specified
   * to show information about a specific list. Path data can be
   * found in the master list retrieved by specifying no path.
   *
   * @param String $path - Optionally specify a path.
   * @return XML document containing list information
   */
  public function get_lists_xml($path=''){
    $url='https://api.constantcontact.com/ws/customers/'.$this->user.'/lists'.$path;
    $post='';

    $response=$this->fetch($url, $post);
    return $response;
  }


  /**
   * Retrieves the XML service document
   *
   * @return XML service document
   */
  public function get_service_doc_xml(){
    $url='https://api.constantcontact.com/ws/customers/'.$this->user.'/';
    $post='';

    $response=$this->fetch($url, $post);
    return $response;
  }

  /**
   * Sets your API key
   *
   * @param String $api_key - Your API Key
   */
  public function set_api_key($api_key){
    $this->api_key=$api_key;
  }

  /**
   * Set your ConstantContact Password
   *
   * @param String $pass - Your Password
   */
  public function set_pass($pass){
    $this->pass=$pass;
  }

  /**
   * Set your ConstantContact Username
   *
   * @param String $user - Your Username
   */
  public function set_user($user){
    $this->user=$user;
  }

  /**
   * Converts XML data into a nested array
   *
   * @param String $contents - XML string
   * @param Integers $get_attributes - Include attributes (default 1)
   * @return Nested associative array
   */
  public function xml_to_array($contents, $get_attributes=1) {

    if(!$contents) return array();

    if(!function_exists('xml_parser_create')) {
      return array();
    }

    $parser = xml_parser_create();
    xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
    xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
    xml_parse_into_struct( $parser, $contents, $xml_values );
    xml_parser_free( $parser );

    if(!$xml_values) return;

    $xml_array = array();
    $parents = array();
    $opened_tags = array();
    $arr = array();

    $current = &$xml_array;


    foreach($xml_values as $data) {
      unset($attributes,$value);
      extract($data);

      $result = '';
      if($get_attributes) {
        $result = array();
        if(isset($value)) $result['value'] = $value;
        if(isset($attributes)) {
          foreach($attributes as $attr => $val) {
            if($get_attributes == 1) $result['attr'][$attr] = $val;
          }
        }
      } elseif(isset($value)) {
        $result = $value;
      }

      if($type == "open") {
        $parent[$level-1] = &$current;
        if(!is_array($current) or (!in_array($tag, array_keys($current)))) {
          $current[$tag] = $result;
          $current = &$current[$tag];
        } else {
          if(isset($current[$tag][0])) {
            array_push($current[$tag], $result);
          } else {
            $current[$tag] = array($current[$tag],$result);
          }
          $last = count($current[$tag]) - 1;
          $current = &$current[$tag][$last];
        }
      } elseif($type == "complete") {

        if(!isset($current[$tag])) {
          $current[$tag] = $result;
        } else {
          if((is_array($current[$tag]) and $get_attributes == 0)
          or (isset($current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)) {
            array_push($current[$tag],$result);
          } else {
            $current[$tag] = array($current[$tag],$result);
          }
        }
      } elseif($type == 'close') {
        $current = &$parent[$level-1];
      }
    }
    return($xml_array);
  }
 
}


?>

Highlighted
Developer

Re: Server Migration results in eNews signup failure

Ok, so another update. This is ONLY happening when a user who has previously signed up, and been removed, tries to sign up again.

 

Best,

Lissa

Highlighted
Employee

Re: Server Migration results in eNews signup failure

Hey Martha,

 

Have any of the permissions changed since you did the server migration?  I have looked through your code and it appears to be fine.  If you step through it, where does the error occur?

 

Ryan Davis
Quality Engineer
Highlighted
Employee

Re: Server Migration results in eNews signup failure

Hey Martha,

 

After a second look at your error I think you are getting the wrong error. It looks like you are getting a 409 and which would happen if you try to create a contact that already exists.  Upon getting the 409  and when the error is handled it navigates to a page that does not exist.  Thus you would get a 500 error because its internal and the Page not exist error as well, the page does not exist. 

Ryan Davis
Quality Engineer
Highlighted
Developer

Re: Server Migration results in eNews signup failure

I see...but if the contact has been previously removed, should that happen?

 

Many thanks!

 

Highlighted
Employee

Re: Server Migration results in eNews signup failure

Hey Martha,

 

Yes, as each contact is given a unique ID to your account.  If this an email address already has an ID, it would conflict.  Thus the 409.  You would want to do a search, if it exists then you would do a PUT.  Here is an example i made using our new wrapper.

 

<?php 
/****************************************************************************************
 * 
 * 		Please note that this is just an example, please change the credentials to
 * 		your own constant contact login credentials.  The following code is an example of:
 * 
 * 		Search for contact by email address
 * 		Creating a new contact if it doesen't already exist
 * 		If Contact exists, then update the contact by adding it to a new list
 * 		
 ****************************************************************************************/

// this application uses our new wrapper that can be found on github
// https://github.com/ctctsupport/ctct_php_library

include ('wrapper/ConstantContact.php');
	// Connecting to your account
	$ConstantContact = new ConstantContact("basic", "apikey", "Username", "Password");

	// Get potential contact lists
	$lists = $ConstantContact->getLists();
	// Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50
	
	// Email address here is used for testing purposes
	// NOTE:  This email address will be added to your account if you execute this script,
	//		  you should send this to do-not-mail after your testing
	$emailAddress = "test@test.com";
	
	// Search for our new Email address
	$search = $ConstantContact->searchContactsByEmail($emailAddress);
	
	// If the search didnt return a contact object
	if($search == false)
	{
		// Create a new Contact Object to store data into
		$contactObj = new Contact();
		// Adding multiple lists to this new Contact Object
		$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
		// Set the email address
		$contactObj->emailAddress = $emailAddress;
		// Create the Contact and DONE
		$Contact = $ConstantContact->addContact($contactObj);
		
	} // Otherwise we update our existing
	else 
	{
		
		// Gather data from our previous search and store it into a data type
		$contactObj = $ConstantContact->getContactDetails($search[0]);
		// We need to get the old list and add a new list to it as
		// this request requires a PUT and will remove the lists
		// as they are stored in an array
		array_push($contactObj->lists, $lists['lists'][3]->id );
		
		// Update the contact and DONE
		$UpdateContact = $ConstantContact->updateContact($contactObj);
	}
		

?>

 You can get this new wrapper here if you wish to implement this.

Ryan Davis
Quality Engineer
Highlighted
Developer

Re: Server Migration results in eNews signup failure

Thanks, Ryan, very helfpul.

 

I have another problem seemingly related to the Constant Contact API.

 

On tne website's registration page, (http://www.wmf.org/user/register), I can optionally include checkboxes that sign the user up for two e-newsletters at the same time that they register for the website 'community'.

 

With those checkboxes checked, however, the registration process (for the web site) now fails. Again, this is a new bug that began happening with a recent server migration.

 

So on this page:

http://www.wmf.org/user/register

 

Once the user clicks "Create New Account", they should get redirected to a thank you page (http://www.wmf.org/content/thank-you), and an email should be sent out allowing them to click on a link to complete their registration.  Niether of these two things happen, on the new server, when the Constant Contact checkboxes are checked. If they are unchecked, then the registration process completes.

 

Again, the user is being inserted into the Constant Contact list, but those checkboxes being checked are somehow causing the WEBSITE registration process to fail.

 

Thanks for any thoughts on this you might have! I've had 6 server technicans at the host company scratching their heads over this for two weeks:)

 

Best,

Lissa

 

 

Highlighted
Employee

Re: Server Migration results in eNews signup failure

If you would like to post your code or PM it to me, I would be happy to take a look. 

Ryan Davis
Quality Engineer
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured