I know how to generate PDF using mPDF library and send it as attachment using PHPMailer - something like this:
...
$emailAttachment = $mpdf->Output('file.pdf', 'S');
$mail = new PHPMailer();
$mail->AddStringAttachment($emailAttachment, 'file.pdf', 'base64', 'application/pdf');
...
But what if I generate PDF in separate PHP file (that should not be modified) - like this - invoice.php:
...
$mpdf = new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
How can I attach this dynamically created PDF file using PHPMailer? I tried this:
$mail = new PHPMailer();
...
$mail->addStringAttachment(file_get_contents('invoice.php'), 'invoice.pdf', 'base64', 'application/pdf');
$mail->send();
Email is sent with correct content but PDF attachment is corrupted and thus cannot be displayed. How to encode it correctly? I tried few other ways but file is corrupted or is not attached at all (in one case, whole email body was blank).
Thank you for your help in advance! :)