8 core.api.php hook_mail_alter(&$message)
5 core.php hook_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers)
6 core.php hook_mail_alter(&$message)
7 system.api.php 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().


$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.


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


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


function my_module_mail_alter(&$message) {
switch (
$message['id']) {
$message['headers']['From'] = $message['from'] = 'My Site Password Reset <'. $message['from'] .'>';

You can also replace $message['from'] with a hard-coded alternate email address for each case if needed.

How to add mail ids in 'cc'?