I am trying to send an email attachment without using the Mime Mail module or installing any other module.

At the moment the email is being sent and I can receive it but it doesn't have the attachment, it even shows the little paper clip that represent the attachment, but when I click it I get an empty html file by the name attachment.html.

Does anyone have an idea on how to do this without installing any other modules?

P.S I am using the HTMLMAILSYSTEM for sending emails.

     * Implements hook_mail()
    function mymodule_mail($key, &$message, $params) {
      switch ($key) {
        case 'send_report':
          $message['headers'] = array(
            'MIME-Version' => '1.0',
            'Content-Type' => 'text/csv; charset=UTF-8; format=flowed; delsp=yes',
            'Content-Transfer-Encoding' => '8Bit',
            'X-Mailer' => 'Drupal',
            'Content-Disposition' => 'attachment',
          $message['subject']= $params['subject'];
          $message['body'][] = $params['body'];

          if (isset($params['attachment'])) {
            $message['params']['attachments'][] = $params['attachment'];

     * Calls the drupal_mail method which sends the csv
    function send_email() {

      $key = 'send_report';
      $module = 'mymodule';
      $to = "email@mydomain.com";
      $from = variable_get('site_mail');
      $body = "Attached in this email is the report";
      $attachment = array(
        'filecontent' => file_get_contents('/tmp/report.csv'),
        'filename' => 'report.csv',
        'filemime' => 'text/csv',
        'list' => TRUE
      $send = TRUE;
      $params = array(
        'subject' => 'Missing SKU Images Report',
        'body' => $body,
      $language = language_default();
      $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
      if ($result['result'] == TRUE) {
        drupal_set_message(t('Your message has been sent.'));
      else {
        drupal_set_message(t('There was a problem sending your message and it was not sent.'), 'error');

Note: I read the question about "Send attachments with drupal_mail". Most of the answers mentioned are using the MIMEMAIL module which I can't do (because I am not allowed to install any modules).

  • Possible duplicate of Send attachments with drupal_mail – make-me-alive May 15 '16 at 13:54
  • I read that question and most of the answers mentioned using the MIMEMAIL module which I can't do because I am not allowed to install any modules. – Ian Ian May 15 '16 at 14:08
  • 1
    c d 2nd last answers it says 2 use 'filecontent' =>file_get_contents('some/file/path'); i suppose that was what u wanted.. – make-me-alive May 15 '16 at 14:14
  • Yes, thank you I have the updated the cose and that's made it better, however when I click the file "report.csv" (in the email) it's still empty. Do you know what's causing this? – Ian Ian May 15 '16 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.