MPDF电子邮件附件发送空白PDF [英] MPDF E-mail Attachment Sends Blank PDF

查看:184
本文介绍了MPDF电子邮件附件发送空白PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功使用mpdf生成了PDF,并已通过下载PDF进行了验证.但是,当我将PDF作为电子邮件附件发送时,我收到了一个空白的PDF,Adobe Reader出现了内存不足"错误.下面是我的代码:

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 an "Out of Memory" error by Adobe Reader. Below is my code:

<?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 = 'sample@sample.com';
$from_name = 'KIREA';
$from_mail = 'NoReply@kirea.ca';
$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 receipts@kirea.ca";;
$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最终空白的问题,是否有任何想法?谢谢.

Are there any ideas as to why the PDF is ending up blank after being sent as an e-mail attachment? Thank you.

推荐答案

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');

在电子邮件中使用$content

这篇关于MPDF电子邮件附件发送空白PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆