hook_mail_alter

Versions
5
hook_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers)
6 – 7
hook_mail_alter(&$message)

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

Code

developer/hooks/core.php, line 1037

<?php
function hook_mail_alter(&$message) {
  if ($message['id'] == 'modulename_messagekey') {
    $message['body'][] = "--\nMail sent out from " . variable_get('sitename', t('Drupal'));
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.