You are here

public function MandrillTestService::send in Mandrill 8

Abstracts sending of messages using PHP's built-in mail() function instead of Mandrill's sending API.

Parameters

array $message: A message array formatted for Mandrill's sending API.

Return value

bool TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

Overrides MandrillService::send

File

src/MandrillTestService.php, line 43

Class

MandrillTestService
Test Mandrill service.

Namespace

Drupal\mandrill

Code

public function send($message) {
  if (\Drupal::config('system.mail')
    ->get('interface.default') === 'test_mail_collector') {
    $captured_emails = \Drupal::state()
      ->get('system.test_mail_collector') ?: [];
    $captured_emails[] = $message;
    \Drupal::state()
      ->set('system.test_mail_collector', $captured_emails);
    return TRUE;
  }
  return parent::send($message);
}