You are here

function _campaignmonitor_add_subscriber in Campaign Monitor 6.3

Same name and namespace in other branches
  1. 5.2 campaignmonitor.module \_campaignmonitor_add_subscriber()
  2. 5 campaignmonitor.module \_campaignmonitor_add_subscriber()
  3. 6 campaignmonitor.module \_campaignmonitor_add_subscriber()
  4. 6.2 campaignmonitor.module \_campaignmonitor_add_subscriber()

Subscribe a user to a newsletter list, by e-mail, name and custom fields.

Parameters

string $api_key:

int $list_id:

string $name:

string $email:

array $custom_fields:

boolean $show_errors:

Return value

boolean, TRUE if subscription succeeded else FALSE.

3 calls to _campaignmonitor_add_subscriber()
campaignmonitor_subscribe_form_submit in ./campaignmonitor.module
campaignmonitor_user_page_form_submit in includes/campaignmonitor.user_page.inc
Implementation of user page form submit.
_campaignmonitor_altered_form_submit in ./campaignmonitor.module

File

./campaignmonitor.module, line 604
Module that plugs in Campaign Monitor functionality to your Drupal web site. For Campaign Monitor information see: http://www.campaignmonitor.com/

Code

function _campaignmonitor_add_subscriber($api_key, $list_id, $name, $email, $custom_fields = array(), $show_errors = FALSE) {
  $cm = new CampaignMonitor($api_key, $client_id, $campaign_id, $list_id);
  if (count($custom_fields) > 0) {
    $result = $cm
      ->subscriberAddAndResubscribeWithCustomFields($email, $name, $custom_fields);
  }
  else {
    $result = $cm
      ->subscriberAddAndResubscribe($email, $name);
  }
  if (empty($result) || $result['anyType']['Code'] != 0) {
    if (empty($result)) {
      watchdog('campaignmonitor', 'There was a problem with the connection to Campaign Monitor.');
    }
    else {
      watchdog('campaignmonitor', 'Code - %code, Message - %message', array(
        '%code' => $result['anyType']['Code'],
        '%message' => $result['anyType']['Message'],
      ));
    }
    drupal_set_message(CM_SUBSCRIPTION_ERROR, 'error', FALSE);
    return FALSE;
  }
  else {
    $details = _campaignmonitor_get_list_detail($api_key, $list_id);
    drupal_set_message(str_replace('%list', $details['Title'], CM_SUBSCRIPTION_SUCCESS), 'status');
    return TRUE;
  }
}