Currently in any implementation of hook_mail_alter(), $message['body'] can be either an array or a string, but that is not documented very well. The standard throughout core seems to use an array for e-mail bodies, so why can't we just standardize it? Here are my findings from #331960: Fatal error: [] operator not supported for strings:

Modules can either pass an array or a string as a mail 'body' to drupal_mail(). Watcher.module and comment_subscribe.module use a string instead of an array.

function _watcher_email_notifications_send_message($qmsg) {
...
  // Body
  $body = html_entity_decode(strip_tags(filter_xss($qmsg->message)), ENT_QUOTES);
...
  $params['body'] = $body;
...
  // Send email
  $message = drupal_mail('watcher', 'notification', $to, $language, $params, $from, true);

Note that the message body doesn't 'officially' become an array until after mail_alter calls are finished (see drupal_mail):

  // Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
  drupal_alter('mail', $message);

  // Concatenate and wrap the e-mail body.
  $message['body'] = is_array($message['body']) ? drupal_wrap_mail(implode("\n\n", $message['body'])) : drupal_wrap_mail($message['body']);

Comments

dave reid’s picture

Issue tags: +Mollom

Cross-tagging for core issues that need to be fixed for the Mollom.module.

dave reid’s picture

Status: Active » Closed (duplicate)

This is a duplicate of #455172: drupal_mail() example encourages $message['body'] to be set as a string rather than array. Wish we had our 'search for duplicate issues first' since this was created first. :)

joshmiller’s picture

Issue tags: -DrupalWTF

Cleaning up DrupalWTF list... Since this is a duplicate, removing tag...

dave reid’s picture

@joshmiller: You know you don't need to remove tags? You can just select 'Open Issues' and it won't show closed/wont'fix/duplicate/etc issues. For those of us subscribed to e-mails we're getting emails when you update all these.