Through drupal_mail('mymodule', ...) I'm trying to send e-mails with four (4) attachments. When I send an e-mail, I is delivered instantly with the correct subject and body. However, I only get the first attachment, not the other three (3).
Details below. Does anyone have an idea what's going on here?
What I've tried
So far I've tried several (not notable) combinations of headers, providing attachments as content of with filepath only, and some variations suggested in related Q&As. Attachment structure is per the documentation in the module at mimemail.module::mimemail_prepare_message() (~line 309).
The e-mails I'm sending are HTML emails, with attachments, routed through custom SMTP settings (sending through SendGrid).
The total size of the emails is well below the 8MB limit Drupal seems to impose.
In the bottom code block of my post I have added a var_dump() of my $message. This dump also contains the array $message['params], which contains the $params I've passed to drupal_mail('mymodule', ...).
Technical details:
Installed mail modules:
Mail configuration, through Mail System module:
- Site-wide default MailSystemInterface class:
HTMLMailSystem__SmtpMailSystem - HTML Mail module class:
HTMLMailSystem__SmtpMailSystem - Mime Mail module class:
MimeMailSystem
Custom mail hooks:
/** * Implements hook_mail(). */ function mymodule_mail($key, &$message, $params) { if (!empty($params['subject'])) { $message['subject'] = $params['subject']; } if (!empty($params['body'])) { $message['body'] = $params['body']; } if (!empty($params['attachments'])) { $message['attachments'] = $params['attachments']; } if (!empty($params['Cc'])) { $message['Cc'] = $params['Cc']; } } /** * Implements hook_mail_alter(). */ function mymodule_mail_alter(&$message) { if (!empty($message['params']['headers'])) { $message['headers'] = array_merge($message['headers'], $message['params']['headers']); } } A var_dump of $message, called at the bottom of mymodule_mail_alter() (data partially faked to protect client):
array (size=12) 'id' => string 'mymodule_mymail' (length=38) 'module' => string 'mymodule' (length=10) 'key' => string 'mymail' (length=27) 'to' => string '[email protected]' (length=30) 'from' => string '[email protected]' (length=35) 'language' => string 'nl' (length=2) 'params' => array (size=4) 'headers' => array (size=2) 'MIME-Version' => string '1.0' (length=3) 'Content-Type' => string 'multipart/mixed; text/html; text/plain; charset=UTF-8; format=flowed; delsp=yes' (length=79) 'subject' => string 'Title' (length=46) 'body' => array (size=1) 0 => string '<p>HTML</p><p>Mail</p>'... (length=555) 'attachments' => array (size=4) 0 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_mail.txt' (length=11) 'filemime' => string 'text/plain' (length=10) 'filepath' => null 1 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_mail_2.txt' (length=13) 'filemime' => string 'text/plain' (length=10) 'filepath' => null 2 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_file_3.txt' (length=32) 'filemime' => string 'text/plain' (length=10) 'filepath' => null 3 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_mail.txt' (length=11) 'filemime' => string 'text/plain' (length=10) 'filepath' => null 'send' => boolean true 'subject' => string 'Title' (length=46) 'body' => array (size=1) 0 => string '<p>HTML</p><p>Mail</p>'... (length=555) 'headers' => array (size=7) 'MIME-Version' => string '1.0' (length=3) 'Content-Type' => string 'multipart/mixed; text/html; text/plain; charset=UTF-8; format=flowed; delsp=yes' (length=79) 'Content-Transfer-Encoding' => string '8Bit' (length=4) 'X-Mailer' => string 'Drupal' (length=6) 'Return-Path' => string '[email protected]' (length=35) 'Sender' => string '[email protected]' (length=35) 'From' => string '[email protected]' (length=35) 'attachments' => array (size=4) 0 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_mail.txt' (length=11) 'filemime' => string 'text/plain' (length=10) 'filepath' => null 1 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_mail_2.txt' (length=13) 'filemime' => string 'text/plain' (length=10) 'filepath' => null 2 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_file_3.txt' (length=32) 'filemime' => string 'text/plain' (length=10) 'filepath' => null 3 => array (size=4) 'filecontent' => string 'test file' (length=16) 'filename' => string 'test_mail.txt' (length=11) 'filemime' => string 'text/plain' (length=10) 'filepath' => null