You are here

public function CampaignMonitor::updateSubscriberEmail in Campaign Monitor 8

Updates the subscriber e-mail address for a given list.

Parameters

array $listId: The unique Campaign Monitor list ID.

string $oldEmail: The old e-mail address.

string $email: The new e-mail address.

File

src/CampaignMonitor.php, line 894
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 updateSubscriberEmail($listId, $oldEmail, $email) {
  if ($obj = $this
    ->createSubscriberObj($listId)) {
    $result = $obj
      ->update($oldEmail, [
      'EmailAddress' => $email,
      'Resubscribe' => TRUE,
    ]);
    if (!$result
      ->was_successful()) {
      $this
        ->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
      return FALSE;
    }

    // Remove the old e-mail address from the subscriber cache.
    $this
      ->removeSubscriberFromCache($listId, $oldEmail);
    return TRUE;
  }
}