I'm using mimemail module in Drupal to send e-mails with attachments. The e-mails are correctly sent, but the attachments not. This is the code I use (I've just enabled the module):
$sender = '[email protected]';
$recipient = '[email protected]';
$subject = 'New order';
$body = 'Please, see the attachment.';
$plaintext = TRUE;
$headers = array();
$attachments[]=array(
'filepath' => 'invoices/sample.pdf',
'filemime' => 'application/pdf',
);
mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, $attachments, $mailkey);
In order to be sure the path to the pdf attachment is correct I've written this line to download the attachment from browser and it works.
header('Location: invoices/sample.pdf');
Also,I've tried this alternative code. But still nothing...
$file = new stdClass();
$file->filename = 'sample.pdf';
$file->filepath = 'invoices/sample.pdf';
$file->filemime = 'application/pdf';
mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, array($file), $mailkey);
ps. i don't think this, but is maybe because my hosting disallow to send attachments ? thanks
There are two issue reports opened for the Mime Mail module.
In Attachments specified with absolute local paths are not added, the OP reports that attachments specified using absolute paths don't work; there is a proposed patch to solve the issue. In that issue, it's suggested to change the code to send an email with attachements from
header('Location: invoices/sample.pdf');
$sender = '[email protected]';
$recipient = '[email protected]';
$subject = 'New order';
$body = 'Please, see the attachment.';
$plaintext = TRUE;
$headers = array();
$attachments[] = array(
'filepath' => 'invoices/sample.pdf',
'filemime' => 'mime/type',
);
mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, $attachments, $mailkey);
to
header('Location: invoices/sample.pdf');
$sender = '[email protected]';
$recipient = '[email protected]';
$subject = 'New order';
$body = 'Please, see the attachment.';
$plaintext = TRUE;
$headers = array();
$attachments[] = array(
'filepath' => 'invoices/sample.pdf',
'filemime' => 'mime/type',
'filename' => 'sample.pdf',
'list' => TRUE,
);
mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, $attachments, $mailkey);
In mimemail + smtp + attachments not working with attachments, the OP reports that attachments are not shown when using SMTP; in the same report, another user reports that he is not using SMTP, but the attachements are not shown when the email is sent through Rules.