You are here

function _campaignmonitor_add_subscriber in Campaign Monitor 5

Same name and namespace in other branches
  1. 5.2 campaignmonitor.module \_campaignmonitor_add_subscriber()
  2. 6.3 campaignmonitor.module \_campaignmonitor_add_subscriber()
  3. 6 campaignmonitor.module \_campaignmonitor_add_subscriber()
  4. 6.2 campaignmonitor.module \_campaignmonitor_add_subscriber()
3 calls to _campaignmonitor_add_subscriber()
campaignmonitor_form_submit in ./campaignmonitor.module
campaignmonitor_general_form_submit in ./campaignmonitor.module
campaignmonitor_user_form_submit in ./campaignmonitor.module

File

./campaignmonitor.module, line 425

Code

function _campaignmonitor_add_subscriber($api_key, $list_id, $name, $email, $show_errors = false) {
  $client = $client = _campaignmonitor_create_client();
  try {

    //make soap call
    $result = $client
      ->__soapCall("Subscriber.AddAndResubscribe", array(
      new SoapVar($api_key, XSD_STRING, null, null, "ApiKey", "http://app.campaignmonitor.com/api/"),
      new SoapVar($list_id, XSD_INT, null, null, "ListID", "http://app.campaignmonitor.com/api/"),
      new SoapVar($email, XSD_STRING, null, null, "Email", "http://app.campaignmonitor.com/api/"),
      new SoapVar($name, XSD_STRING, null, null, "Name", "http://app.campaignmonitor.com/api/"),
    ), array(
      "soapaction" => "http://app.campaignmonitor.com/api/Subscriber.AddAndResubscribe",
    ));
    if ($result->Code != 0) {
      watchdog('CAMPAIGNMONITOR RESULT: ', 'Code - ' . $result->Code . ', Message - ' . $result->Message);
      drupal_set_message("There was an error joining to newsletter.", 'error');
    }
    else {
      drupal_set_message("You have successfully been added.", 'status');
    }
  } catch (SoapFault $e) {
    if ($show_errors) {
      watchdog('ERROR IN CAMPAIGNMONITOR', 'There was an error joining to newsletter: ' . $e->faultstring, WATCHDOG_ERROR);
      drupal_set_message("There is an error with the newsletter server. Please try again later.", 'error');
    }
  }
}