I was looking a way to send email with attachments in drupal, to create a simple module which sends email to users with attached images.

I try to do it with drupal_mail() function. but results were no so great! so when finding alternative, I found a module called mimemail module which allow send
email attachments with less pain.

even though i sounds like pretty straight-forward task. I have dig little harder find the prefect combination.

header('Location: invoices/sample.pdf');

 $sender = 'mycompany@company.com';
 $recipient = 'myemail@email.com';
 $subject = 'New order';
 $body = 'Please, see the attachment.'; //body text in HTML format
 $plaintext = TRUE; //whether to send messages in plaintext-only
 $headers = array();
   $attachments[] = array(
    'filepath' => 'sites/default/images/sample.jpg' , //you have to use relative paths.
    'filename' => 'download.jpg' , // can use any alias name here
    'filemime' => 'image/jpeg' , // mime file type
 'list' => TRUE,
 );

mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, $attachments, $mailkey, $send= True);




Leave a Reply