1 email_example.module email_example_mail_alter(&$message)

Implements hook_mail_alter().

This function is not required to send an email using Backdrop's mail system.

Hook_mail_alter() provides an interface to alter any aspect of email sent by Backdrop. You can use this hook to add a common site footer to all outgoing email, add extra header fields, and/or modify the email in any way. HTML-izing the outgoing email is one possibility.

Related topics

File

modules/examples/email_example/email_example.module, line 131
Hook implementations for the Email Example module.

Code

function email_example_mail_alter(&$message) {
  // For the purpose of this example, modify all the outgoing messages and
  // attach a site signature. The signature will be translated to the language
  // in which message was built.
  $options = array(
    'langcode' => $message['language']->langcode,
  );

  $signature = t("\n--\nMail altered by email_example module.", array(), $options);
  if (is_array($message['body'])) {
    $message['body'][] = $signature;
  }
  else {
    // Some modules use the body as a string, erroneously.
    $message['body'] .= $signature;
  }
}