我已成功生成使用mpdf的PDF,我已通过下载PDF进行验证。但是,当我通过电子邮件附件发送PDF时,Adobe Reader会收到一封空白的PDF,其中包含“内存不足”错误。以下是我的代码:MPDF电子邮件附件发送空白PDF
<?php
include("MPDF57/mpdf.php");
ob_start();
include "Receipt_Template_2.php";
$template = ob_get_contents();
ob_end_clean();
$mpdf=new mPDF('','A4','','',32,25,27,25,16,13,'L');
mpdf->WriteHTML($template);
$content = $mpdf->Output($template, 'S');
$content = chunk_split(base64_encode($content));
$mailto = '[email protected]';
$from_name = 'KIREA';
$from_mail = '[email protected]';
$uid = md5(uniqid(time()));
$subject = 'KIREA Donation Receipt';
$message = "Thank you for your donation!\n\nAttached is the receipt concerning the donation. If you have any questions, please e-mail us at [email protected]";;
$filename = $pdfName;
$header = "From: ".$from_name." <".$from_mail.">\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\n";
$header .= "This is a multi-part message in MIME format.\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\n";
$header .= "Content-Transfer-Encoding: 7bit\n";
$header .= $message."\n\r\n";
$header .= "--".$uid."\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\n\n";
$header .= $content."\n\n";
$header .= "--".$uid."--";
$is_sent = @mail($mailto, $subject, "", $header);
$mpdf->Output();
exit;
?>
是否有任何想法,为什么PDF作为电子邮件附件发送后变为空白?谢谢。
是你能解决这个问题?具有相同的概率。 – MizAkita
这可能有所帮助:http://mpdf1.com/manual/index.php?tid=373 –
手册处于离线状态。改为使用它:https://mpdf.github.io/real-life-examples/e-mail-a-pdf-file.html – Sol