The body of the message is set by the implementation of hook_mail()
done from the module sending the message. The code invoking that hook is the following one. (See MailManager::doMail()
, the method called from MailManager::mail()
.)
// Bundle up the variables into a structured array for altering.
$message = array(
'id' => $module . '_' . $key,
'module' => $module,
'key' => $key,
'to' => $to,
'from' => $site_mail,
'reply-to' => $reply,
'langcode' => $langcode,
'params' => $params,
'send' => TRUE,
'subject' => '',
'body' => array(),
);
// Build the default headers.
$headers = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal',
);
// To prevent email from looking like spam, the addresses in the Sender and
// Return-Path headers should have a domain authorized to use the
// originating SMTP server.
$headers['Sender'] = $headers['Return-Path'] = $site_mail;
$headers['From'] = $site_config->get('name') . ' <' . $site_mail . '>';
if ($reply) {
$headers['Reply-to'] = $reply;
}
$message['headers'] = $headers;
// Build the email (get subject and body, allow additional headers) by
// invoking hook_mail() on this module. We cannot use
// moduleHandler()->invoke() as we need to have $message by reference in
// hook_mail().
if (function_exists($function = $module . '_mail')) {
$function($key, $message, $params);
}
As you see, $message['body']
is set to an empty array before passing it to hook_mail()
. If your module doesn't implement hook_mail()
, $message['body']
will stay an empty array, if there aren't other module that implement hook_mail_alter()
.
The comment before the code invoking hook_mail()
is also explicit about what expecting from that hook: get subject and body, allow additional headers.
As usual, that is the default implementation of the mail manager. It could be a different mail manager sets the message body to a more significant value, but a module should not depend on the mail manager doing it.
As side note, Drupal doesn't use $message['message']
as your code does.
hook_mail($key, &$message, $params) {
code ?