Same name and namespace in other branches
  1. 10 core/core.api.php \hook_mail_alter()
  2. 6.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 the emails sent by Drupal. You can use this hook to add a common site footer to all outgoing emails; add extra header fields and/or modify the mails sent out in any way. HTML-izing the outgoing mails is one possibility. See also drupal_mail().

Parameters

$mailkey: A key to indetify the mail sent. Look into the module source codes for possible mailkey values.

$to: The mail address or addresses where the message will be send 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: Message to be sent. Drupal will format the correct line endings for you.

$from: The From, Reply-To, Return-Path and Error-To headers in $headers are already set to this value (if given).

$headers: Associative array containing the headers to add. This is typically used to add extra headers (From, Cc, and Bcc).

Return value

The return value is discarded. Modify the parameters directly.

Related topics

File

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

Code

function hook_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {
  $body .= "\n\n--\nMail sent out from " . variable_get('sitename', t('Drupal'));
}