ProMailerSubscribers::importCSV()

Import subscribers from given CSV file

First line must contain header line with one of them being "email". Columns other than "email" are placed in the "data" array of each subscriber. Imported subscribers are considered "confirmed". To import subscriber removals, prepend email address with a minus, i.e. "-you

Usage

// basic usage
$array = $proMailerSubscribers->importCSV(string $csvFile, $list);

// usage with all arguments
$array = $proMailerSubscribers->importCSV(string $csvFile, $list, array $options = []);

Arguments

NameType(s)Description
$csvFilestring
$listint ProMailerList
$options (optional)array
  • `delimiter' (string): Delimiter for CSV fields, ",", ";", "\t", or "a" for auto-detect Default:','
  • length (int): Maximum line length/chunk size Default:4096
  • confirmed (bool|string): Are these already opt-in/confirmed subscribers? Default:true

Return value

array bool

Returns false on fail or on success returns array with counts of 'added', 'failed', 'skipped', 'removed'


Hooking ProMailerSubscribers::importCSV(…)

You can add your own hook events that are executed either before or after the ProMailerSubscribers::importCSV(…) method is executed. Examples of both are included below. A good place for hook code such as this is in your /site/ready.php file.

Hooking before

The 'before' hooks are called immediately before each ProMailerSubscribers::importCSV(…) method call is executed. This type of hook is especially useful for modifying arguments before they are sent to the method.

$this->addHookBefore('ProMailerSubscribers::importCSV', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $ProMailerSubscribers = $event->object;

  // Get values of arguments sent to hook (and optionally modify them)
  $csvFile = $event->arguments(0);
  $list = $event->arguments(1);
  $options = $event->arguments(2);

  /* Your code here, perhaps modifying arguments */

  // Populate back arguments (if you have modified them)
  $event->arguments(0, $csvFile);
  $event->arguments(1, $list);
  $event->arguments(2, $options);
});

Hooking after

The 'after' hooks are called immediately after each ProMailerSubscribers::importCSV(…) method call is executed. This type of hook is especially useful for modifying the value that was returned by the method call.

$this->addHookAfter('ProMailerSubscribers::importCSV', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $ProMailerSubscribers = $event->object;

  // An 'after' hook can retrieve and/or modify the return value
  $return = $event->return;

  // Get values of arguments sent to hook (if needed)
  $csvFile = $event->arguments(0);
  $list = $event->arguments(1);
  $options = $event->arguments(2);

  /* Your code here, perhaps modifying the return value */

  // Populate back return value, if you have modified it
  $event->return = $return;
});

ProMailerSubscribers methods and properties

API reference based on ProcessWire core version 3.0.255