Attachment added through hook_mail_alter() is making no effect I'm trying to add one pdf attachment to the mail sent on webform submission. I'm using hook_mail_alter() to add attachments to the mail.
This is the code I am using.
function webfpdf_mail_alter(&amp;$message) {
$attach = genpdf($message['params']['message']);
$message['params']['attachments'][] = $attach;
dpm($message);
return $message;
}
The output message shown by dpm() shows attachment, but the email doesn't contain attachments.
This is the output of dpm().
attachments (Array, 1 element)
0 (String, 568525 characters ) Content-Type: application/pdf; name=&quot;Webform-...
Content-Type: application/pdf;
 name=&quot;Webform-submission.pdf&quot;
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename=&quot;Webform-submission.pdf&quot;

cSA4NS4wNCAwIDAgMzMuNzMgMjguM......
..../****base64data*****/.....
..... ;
body (Array, 1 element)
headers (Array, 7 elements)
MIME-Version (String, 3 characters ) 1.0
Content-Type (String, 24 characters ) text/html; charset=UTF-8
Content-Transfer-Encoding (String, 4 characters ) 8Bit
X-Mailer (String, 27 characters ) Drupal Webform (PHP/5.3.29)
Return-Path (String, 35 characters ) enquires@xxxxxxx.org
Sender (String, 35 characters ) enquires@xxxxxxx.org
From (String, 28 characters ) &quot;LESS&quot; &lt;support@xxxxxx.com&gt;

Can anyone help me to fix this?
If you're not already using it, I think you need MIME Mail or something similar to handle attachments, and when you do, your attachment needs to be added as an array of arrays rather than an array.
This is what the README file says.

You can use the following optional parameters to build the e-mail:

'plain': Boolean, whether to send messages in plaintext-only (optional, default is FALSE).
'plaintext': Plaintext portion of a multipart e-mail (optional).
'attachments': Array of arrays with the path or content, name and MIME type of the file (optional).
'headers': A keyed array with headers (optional).