I have successfully generated a PDF using mpdf, which I have verified by downloading the PDF. However, when I send the PDF as an e-mail attachment I receive a blank PDF with
If you can use swiftmailer, you can attach a MPDF generated PDF to the email, quite easily as follows:
<?php
require_once $swift_mailer_path.'swift_required.php';
$transporter = Swift_SmtpTransport::newInstance($smtp_host, $smtp_port, $smtp_protocol)
->setUsername($smtp_username')
->setPassword($smtp_password');
$mailer = Swift_Mailer::newInstance($transporter);
$message = Swift_Message::newInstance('Email Subject')
->setFrom(array($from_email => $from_name))
->setTo($to_email)
->setBody($email_body);
$attachment = Swift_Attachment::newInstance($mpdf->Output($pdf_path, "S"), $pdf_file_name, 'application/pdf');
$message->attach($attachment);
$message->setContentType("text/html");
$result = $mailer->send($message);
?>
Here is the Reference.
mpdf->WriteHTML($template);
$content = $mpdf->Output($template, 'S');
You are wrong at here you are not taking the object on which your data is written
please replace below code with above to get correct result.
$pdfdata=mpdf->WriteHTML($template);
$content = $mpdf->Output('' , 'S');
use $content
in your email