Same name and namespace in other branches
  1. 10 core/core.api.php \hook_mail_alter()
  2. 5.x developer/hooks/core.php \hook_mail_alter()
  3. 7.x modules/system/system.api.php \hook_mail_alter()
  4. 8.9.x core/core.api.php \hook_mail_alter()
  5. 9 core/core.api.php \hook_mail_alter()

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 any way. HTML-izing the outgoing email is one possibility. See also drupal_mail().

Parameters

$message: A structured array containing the message to be altered. Keys in this array include:

  • 'id' An id to identify the mail sent. Look at module source code or drupal_mail() for possible id values.
  • 'to' The mail address or addresses the message will be sent to. The formatting of this string must comply with RFC 2822.
  • 'subject' Subject of the e-mail to be sent. This must not contain any newline characters, or the mail may not be sent properly.
  • 'body' An array of lines containing the message to be sent. Drupal will format the correct line endings for you.
  • 'from' The address the message will be marked as being from, which is either a custom address or the site-wide default email address.
  • 'headers' Associative array containing mail headers, such as From, Sender, MIME-Version, Content-Type, etc.
  • 'params' An array of optional parameters supplied by the caller of drupal_mail() that is used to build the message before hook_mail_alter() is invoked.
  • language' The language object used to build the message before hook_mail_alter() is invoked.

Related topics

1 invocation of hook_mail_alter()
drupal_mail in includes/mail.inc
Compose and optionally send an e-mail message.

File

developer/hooks/core.php, line 1106
These are the hooks that are invoked by the Drupal core.

Code

function hook_mail_alter(&$message) {
  if ($message['id'] == 'modulename_messagekey') {
    $message['body'][] = "--\nMail sent out from " . variable_get('sitename', t('Drupal'));
  }
}