电子邮件发送与PDF附件工作但无法打开该PDF甚至在下载后也没有打开

时间:2016-05-21 13:18:53

标签: php html mysql css

我正在使用以下代码,但无法理解我在哪里做错了什么?

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// download fpdf class (http://fpdf.org)
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$html = "<h1>This is html template</h1>";
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("certificate","landscape");
$dompdf->render();
$pdfoutput= $dompdf->output();
$subject = "Mail Out Certificate";
$message = '<h1>Certificate</h1>';
$uid = 1;
$filename = "certificate.pdf";

$from_name = "lifemadeeasy";
$from_mail = "example@gmail.com";
$replyto   = "example1@gmail.com";
$mailto    = "example2@gmail.com";
$header    = "From: " . $from_name . " <" . $from_mail . ">\n";
$header .= "Reply-To: " . $replyto . "\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\n\n";
$emessage = "--" . $uid . "\n";
$emessage .= "Content-type:text/html; charset=iso-8859-1\n";
$emessage .= "Content-Transfer-Encoding: 7bit\n\n";
$emessage .= $message . "\n\n";
$emessage .= "--" . $uid . "\n";
$emessage .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"\n"; // use different content types here
$emessage .= "Content-Transfer-Encoding: base64\n";
$emessage .= "Content-Disposition: attachment; filename=\"" . $filename . "\"\n\n";
$emessage .= $pdfoutput . "\n\n";
$emessage .= "--" . $uid . "--";
mail($mailto, $subject, $emessage, $header);
echo "success";



?>

执行此代码后,我收到带有pdf附件的电子邮件,但pdf未打开。在那个pdf我必须显示来自表格数据的输入。我尝试使用fpdf也会遇到同样的问题。

0 个答案:

没有答案