[development] Fwd: E-mail attachments
Rob Thorne
rob at torenware.com
Sun Dec 29 23:47:34 UTC 2013
I don't see anything obviously wrong in your sample, but after comparing your implementation with mine from a recent project, I see a couple of differences:
1. You mention using the mimemail module, but are you also using the mailsystem module? The simplest explanation would be that mimemail is not getting invoked at all.
2. If I recall correctly, some fields you can set in the "message" array upstream can get unset before hook_mail is called for you. So you may need to put these items into your "params" array and hammer them in as part of your hook_mail implementation. My code looks like this:
Sending the mail:
$mail_params = array(
'subject' => $settings['subject'],
'message' => $settings['message'],
'headers' => array(
'Content-Type' => 'text/html; charset=UTF-8'
),
'attachments' => $attachments,
'voter' => $credit_app,
);
$mail_params['plain'] = FALSE;
$mail_params['plaintext'] = $mail_params['message'];
if (!empty($settings['bcc'])) {
$mail_params['headers']['Bcc'] = $settings['bcc'];
}
$message = drupal_mail('mymodule', 'send-test', $address, $language, $mail_params, $from);
In my hook_mail implementation:
switch ($key) {
case 'send-test':
$message['subject'] = $params['subject'];
$message['body'][] = $params['message'];
$message['headers'] = array_merge($message['headers'], $params['headers']);
break;
}
Note also that I'm setting some parameters that you are not setting ('plain', 'plaintext'); I believe I added those after debugging the problem you're having here.
Hope this helps,
Rob
Rob Thorne
Torenware Networks
On Dec 29, 2013, at 12:50 PM, Muzaffer Tolga Ozses <tolga at ozses.net> wrote:
> Hi,
>
> I keep developing my module, and inside it I am sending e-mail. I am also trying to attach a file, to no avail. I have installed mimemail, I have changed mime type in my code, I have dpm'd everything. dpm gives me correct values, and the subject and body of the e-mail come through, but I couldn't get file attachment to work at all. What else can I do?
>
> Regards,
>
> PS: You can see the code at http://drupalcode.org/sandbox/Kartagis/1543120.git/blob/da47378:/pass2pdf.module#l69
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20131229/6906b52b/attachment.html
More information about the development
mailing list