function email_example_mail_alter

Same name in other branches
  1. 3.x modules/email_example/email_example.module \email_example_mail_alter()
  2. 4.0.x modules/email_example/email_example.module \email_example_mail_alter()

Implements 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 132

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']->language,
    );
    $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;
    }
}