I am trying to implement html mail notifications using htmlmail module. I am not certain if message should be formatted as array in $message["body][]
before the template or passed as a string in $message['body']
.
The reason I am asking is that I first expected the email to be sent in as a string but then saw the HTMLMAILSystem::format
function that flattens the body array:
public function format(array $message) {
$eol = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
// @todo Remove this when issue #209672 gets resolved.
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
if ( !empty($message['headers']['From'])
&& $message['headers']['From'] == $default_from
&& valid_email_address($default_from)
) {
$message['headers']['From'] = '"'
. str_replace('"', '', variable_get('site_name', 'Drupal'))
. '" <' . $default_from . '>';
}
// Collapse the message body array.
if (module_exists('mailmime')) {
$body = $this->formatMailMIME($message);
$plain = $message['MailMIME']->getTXTBody();
}
else {
if (is_array($message['body'])) {
$message['body'] = implode("<br />$eol<br />$eol", $message['body']);
}
$body = theme('htmlmail', $message);
if ($message['body'] && !$body) {
watchdog(
'htmlmail',
'The %theme function did not return any text. Please check your template file for errors.',
array('%theme' => "theme('htmlmail', \$message)"),
WATCHDOG_WARNING
);
$body = $message['body'];
}
So if I understood correctly, message must be preformatted with correct html in $message["body"][]
, but I am not 100% sure there are lots of code-bits involved for email sendouts. I also need to validate if this will allow me to send mail as plaintext?