MPDF E-mail Attachment Sends Blank PDF

别等时光非礼了梦想. 提交于 2019-12-01 01:13:46
vipul tulse
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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!