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(&$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="Webform-...
Content-Type: application/pdf;
Content-Transfer-Encoding: base64
Content-Disposition: attachment;

..... ;
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 ) [email protected]
Sender (String, 35 characters ) [email protected]
From (String, 28 characters ) "LESS" <[email protected]>

Can anyone help me to fix this?

1 Answer 1


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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.