What’s the point to have hook_mail_alter if I already have hook_mail?
For example, I saw that hook_mail_alter is used to add a footer to my mail message. But I could use hook_mail() to add it, instead of using 2 functions… What am I missing?
Maybe it is done to add the footer after some other function is invoked?
hook_mail()should be used from a module to alter its own mail message, whilehook_mail_alter()should be used from a module to alter the message sent by other modules.This is clear from the following code taken from
drupal_mail():$moduleis the first parameter passed todrupal_mail().It’s clear the function doesn’t invoke the implementation of
hook_mail()of every module implementing it, but it invokes the hook just for the module calling the function.There are other differences, such as when the two hooks are invoked (
hook_mail_alter()cannot set the language for the message, which is set beforehook_mail_alter()is invoked), and the parameters they get (hook_mail($key, &$message, $params)versushook_mail_alter(&$message)).