You are here

function workbench_email_mail in Workbench Email 8

Same name and namespace in other branches
  1. 7.3 workbench_email.module \workbench_email_mail()
  2. 7 workbench_email.module \workbench_email_mail()
  3. 2.x workbench_email.module \workbench_email_mail()

Implements hook_mail().

File

./workbench_email.module, line 157
Provides main module functions.

Code

function workbench_email_mail($key, &$message, $params) {
  if (strpos($key, 'template::') === 0) {

    // Mailing one of our templates.
    $message['subject'] = $params['subject'];
    if (\Drupal::moduleHandler()
      ->moduleExists('swiftmailer')) {

      // If swiftmailer exists, we send in HTML.
      $message['headers']['Content-Type'] = 'text/html';
      $message['params']['convert'] = TRUE;
      $message['body'][] = $params['body'];
    }
    else {

      // Strip out any HTML.
      $message['body'][] = MailFormatHelper::htmlToText($params['body']);
    }
  }
}