You are here

function mass_contact_mail in Mass Contact 8

Same name and namespace in other branches
  1. 6 mass_contact.module \mass_contact_mail()
  2. 7 mass_contact.module \mass_contact_mail()

Implements hook_mail().

File

./mass_contact.module, line 77
This is the main code file for the Mass Contact module.

Code

function mass_contact_mail($key, &$message, $params) {
  if (!empty($params['headers'])) {
    foreach ($params['headers'] as $key => $value) {
      $message['headers'][$key] = $params['headers'][$key];
    }
  }
  $message['subject'] = $params['subject'];

  // Message prefix.
  $config = \Drupal::config('mass_contact.settings');
  if ($config
    ->get('message_prefix.value')) {
    $message['body'][] = check_markup($config
      ->get('message_prefix.value'), $config
      ->get('message_prefix.format'));
  }
  $message['body'][] = check_markup($params['body'], $params['format']);

  // Message suffix.
  if ($config
    ->get('message_suffix.value')) {
    $message['body'][] = check_markup($config
      ->get('message_suffix.value'), $config
      ->get('message_suffix.format'));
  }

  // Update the 'From' address.
  $message['from'] = $params['configuration']['sender_mail'];

  // Unset the format so the correct format configured for site's mail can take
  // effect.
  unset($message['params']['format']);
}