You are here

public function CampaignMonitor::unsubscribe in Campaign Monitor 8

Unsubscribe a given user, identified by e-mail address, from a given list.

Parameters

string $listId: The unique Campaign Monitor list ID.

string $email: The e-mail address that identifies the user.

Return value

bool TRUE on success, FALSE otherwise.

File

src/CampaignMonitor.php, line 871
Implementation of the CampaignMonitor class, which is a wrapper class for Campaign Monitor v3 API. It's implemented as a Singleton class and instances are created using the account variables and the static function getConnector(). An example:.

Class

CampaignMonitor

Namespace

Drupal\campaignmonitor

Code

public function unsubscribe($listId, $email) {
  if ($obj = $this
    ->createSubscriberObj($listId)) {
    $result = $obj
      ->unsubscribe($email);
    if (!$result
      ->was_successful()) {
      $this
        ->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
      return FALSE;
    }
    $this
      ->removeSubscriberFromCache($listId, $email);
    return TRUE;
  }
  return FALSE;
}