Skip to content

Instantly share code, notes, and snippets.

@stevesmename
Created June 19, 2013 07:32
Show Gist options
  • Save stevesmename/5812310 to your computer and use it in GitHub Desktop.
Save stevesmename/5812310 to your computer and use it in GitHub Desktop.
Sending pdf as attachment via mimemail (Drupal 6.x)
/**
* Fax an invoice.
*
* @see uc_faxthruemail_action_fax_invoice_form()
*/
function uc_faxthruemail_action_fax_invoice($order, $settings) {
// Token replacements for the subject and body
$settings['replacements'] = array(
'global' => NULL,
'order' => $order,
);
$recipients = array();
$fax_numbers = token_replace_multiple($settings['fax_numbers'], $settings['replacements']);
foreach (explode("\n", $fax_numbers) as $fax_number) {
$recipients[] = trim($fax_number);
}
$settings['message'] = theme('uc_order', $order, $settings['view'], $settings['template']);
$params = array(
'savepdf' => TRUE,
'filename' => 'order' . $order->order_id . '.pdf',
'filelocation' => $settings['filelocation'],
);
$attachments[] = array(
'filepath' => $params['filelocation'] . $params['filename'],
'filename' => $params['filename'],
'filemime' => 'application/pdf',
'list' => TRUE,
);
$pdf = pdfcrowd_api_converthtml($settings['message'], $params);
if (empty($recipients)) {
watchdog('uc_faxthruemail', 'Attempted to fax an invoice with no fax number.', array(), WATCHDOG_ERROR);
return;
}
foreach ($recipients as $fax_number) {
// set subject line
$settings['subject'] = isset($settings['password']) ? $fax_number .' '. $settings['password'] : $fax_number;
$sent = mimemail($settings['from'], 'faxout@faxthruemail.com', $settings['subject'], NULL, NULL, array(), NULL, $attachments, 'uc_faxthruemail');
if (!$sent['result']) {
watchdog('uc_faxthruemail', 'Attempt to fax invoice for order @order_id to @fax failed.', array('@fax' => $fax_number, '@order_id' => $order->order_id), WATCHDOG_ERROR);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment