In hook_mail() I might discover that some part of the email couldn't be generated (maybe when trying to load a variable from an external system it fails).
How can I cancel the sending? I don't want to send an email with an error message in it.
Example code:
function mymodule_mail($key, &$message, $params) {
switch ($key) {
case 'some_email':
$foo = Something::fetchSomething($params['bar']);
if (!$foo) {
// I don't want to send this email any more
}
else {
$message['body'][] = t('Important information about @foo.' ['@foo' => $foo]);
}
break;
}
}
Does that make sense? Or should all parameters be loaded and processed before hook_mail() and in hook_mail() you assume to always have those params available?
to
address maybe? Or don't set a body? It was something like that in D7, probably similar in D8. If all else fails, you can set$message['send'] = FALSE;
inhook_mail_alter()