How I send a mail with attachments using the mimemail module? In drupal 6 it was using the function:

mimemail($sender, $recipient, $subject, $body, $plaintext = NULL, $headers = array(), $text = NULL, $attachments = array(), $mailkey = '', $send = TRUE)

But I am not able to figure out how to do this in drupal 7.

1 Answer 1


Try this code. I'm using it with backup and migrate module

$module = 'backup_migrate';
$key = microtime();
$language = language_default();
$params = array();
$params['attachments'][] = array(
  'filepath' => $attachment->path,
  'filecontent' => 'My attachment.',
  'filename' => $attachment->filename,
  'filemime' => 'text/plain',

$from = $mail->from;

$send = FALSE;
$message = drupal_mail($module, $key, $to, $language, $params, $from, $send);

$message['subject'] = t('Database backup from !site: !file', array('!site' => variable_get('site_name', 'drupal'), '!file' => $attachment->filename));
$message['body'] = t('Database backup attached.') ."\n\n";

// Retrieve the responsible implementation for this message.
$system = drupal_mail_system($module, $key);

// Format the message body.
$message = $system->format($message);

// Send e-mail.
$message['result'] = $system->mail($message);
  • Thank you Pari!!! To learn more about emailing on Drupal 7 there is an example module with an email_example here drupal.org/project/examples
    – Roger
    Sep 12, 2013 at 11:05
  • Unfortunately, it looks like this solution is dependent on the backup and migrate module, which does not make a whole lot of sense in the generic case.
    – Eelke Blok
    Jun 8, 2017 at 14:24

Your Answer

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