You are here

function _campaignmonitor_remove_subscriber in Campaign Monitor 6

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

File

./campaignmonitor.module, line 440

Code

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

    //make soap call
    $result = $client
      ->__soapCall("Subscriber.Unsubscribe", 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.Unsubscribe",
    ));
    if ($result->Code != 0) {
      watchdog('CAMPAIGNMONITOR RESULT: ', 'Code - ' . $result->Code . ', Message - ' . $result->Message);
      drupal_set_message("There was an error unsubscribing from newsletter.", 'error');
    }
    else {
      drupal_set_message("You have successfully been unsubscribed.", 'status');
    }
  } catch (SoapFault $e) {
    if ($show_errors) {
      watchdog('ERROR IN CAMPAIGNMONITOR', 'There was an error unsubscribing from newsletter: ' . $e->faultstring, WATCHDOG_ERROR);
      drupal_set_message("There is an error with the newsletter server. Please try again later.", 'error');
    }
  }
}