Mimemail Attachments - Order Matters
Important note about module order affecting mimemail attachment functionality in Drupal.
I wrote a module that generates PDF and attaches it to an email using hook_mail_alter(). It took me a while to figure out that I cannot add the attachment simply as a string in memory. I had to write it to a temp file first.
function mymodule_mail_alter(&$message) {
$file = array(
'filename' => 'tix.pdf',
'filemime' => 'application/pdf',
'filepath' => $filepath,
);
$message['params']['attachments'][] = $file;
}
On my own machine the above was working perfectly and attachment was going out with the email. But on my hosting provider, it didn’t work. I suspect it had something to do with the order in which modules are enabled and therefore the order in which certain hooks are invoked.
THE ORDER IN WHICH MODULES ARE ENABLED MATTERS.