0

I have a custom module that provides a path that sends an email (mimemail) with a pdf attachment generated from the print_pdf module that comes with the print module.
Here is what my HOOK_mail function looks like.

function custom_send_email_mail($key, &$message, $params) {
  $node = $params['node'];
  $user = $params['user'];

  $message['subject'] = t($node->title.' attached');
  $message['body'] = 'Hello '.$user->name.'<br><br>Please find '.$node->title.' attached.';
  //$message['params']['attachments'][] = $attachment;

  module_load_include('inc', 'print_pdf', 'print_pdf.pages');

  $attachment = array(
    'filecontent' => print_pdf_generate_path($node->nid),
    'filemime' => 'application/pdf',
    'filename' => $node->title.'.pdf',
  );
  $message['params']['attachments'][] = $attachment;

}

The problem I have is that the pdf versions of pages use a template file, which works fine when navigating to the pdf version url, ie. /printpdf/nid but when getting the pdf file string with the (silly named) print_pdf_generate_path() function, it does not use the template file.

1 Answer 1

1

It seems it was a silly mistake on my behalf.

My module defined a custom path to send the email and the theme files for the pdf were in the admin theme folder, so I had to set my path to use the admin theme for the email theme files to be found.
I did so by implementing HOOK_custom_theme.

function custom_send_email_custom_theme() {
  return variable_get('admin_theme');
} 

I will leave this question up as the code may help someone in the future (and maybe me if I need to send an email with attachments again :) )

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.