Skip to content

Instantly share code, notes, and snippets.

@03balogun
Created January 19, 2020 17:32
Show Gist options
  • Select an option

  • Save 03balogun/bd13117c09385d79f6b6eba8f0f57bda to your computer and use it in GitHub Desktop.

Select an option

Save 03balogun/bd13117c09385d79f6b6eba8f0f57bda to your computer and use it in GitHub Desktop.
<?php
...
// custom/modules/AOS_PDF_Templates/generatePdfSendMail.php
if ($task == 'pdf' || $task == 'emailpdf') {
$file_name = $mod_strings['LBL_PDF_NAME'] . "_" . str_replace(" ", "_", $bean->name) . ".pdf";
ob_clean();
try {
$orientation = ($template->orientation == "Landscape") ? "-L" : "";
$pdf = new mPDF('en', $template->page_size . $orientation, '', 'DejaVuSansCondensed', $template->margin_left, $template->margin_right, $template->margin_top, $template->margin_bottom, $template->margin_header, $template->margin_footer);
$pdf->SetAutoFont();
$pdf->SetHTMLHeader($header);
$pdf->SetHTMLFooter($footer);
$pdf->WriteHTML($printable);
if ($task == 'pdf') {
$pdf->Output($file_name, "D");
} else {
$pdfPath = $sugar_config['upload_dir'] . 'attachfile.pdf';
$fp = fopen($pdfPath, 'wb');
fclose($fp);
$pdf->Output($pdfPath, 'F');
$account = BeanFactory::getBean('Accounts', $bean->billing_account_id);
$primary_email = $account->emailAddress->getPrimaryAddress($account);
$mailSubject = "Invoice for ".$bean->name;
$mailBody = "<p>Hello customer, see attachment for your invoice</p>";
/**
* Here are calling the function defined earlier our custom/include/custom_utils.php
* Passing all the required paramenters.
*/
sendEmail($primary_email, $mailSubject, $mailBody, [
'name' => $file_name,
'path' => $pdfPath,
]);
}
} catch (mPDF_exception $e) {
echo $e;
}
} else{
$log->fatal("Error occurred sending mail");
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment