You are here

function email_example_mail_alter in Examples for Developers 6

Same name and namespace in other branches
  1. 8 email_example/email_example.module \email_example_mail_alter()
  2. 7 email_example/email_example.module \email_example_mail_alter()
  3. 3.x modules/email_example/email_example.module \email_example_mail_alter()

Implementation of hook_mail_alter().

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

Hook_mail_alter() provides an interface to alter any aspect of email sent by Drupal. 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 anyway. HTML-izing the outgoing email is one possibility.

Related topics

File

email_example/email_example.module, line 137
Example of how to use Drupal's mail API.

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.
  $signature = t("\n--\nMail altered by email_example module.", array(), $message['language']->language);
  if (is_array($message['body'])) {
    $message['body'][] = $signature;
  }
  else {

    // Some modules use the body as a string, erroneously.
    $message['body'] .= $signature;
  }
}