我有一个填充的 PDF 文件,提交时通过 Adobe Acrobat X 中的发送完成的 pdf 选项将完成的 pdf 文件发送到 processpdf.php 文件(参见下面的代码),代码使用 $HTTP_RAW_POST_DATA 获取原始数据并通过电子邮件发送它。它可以通过电子邮件发送,我收到了 pdf,但 PDF 无法在 chrome/acrobat 或任何东西中打开,因为它说它已损坏。我在这里做错了什么?
我正在使用 PHP5、Adobe Acrobat X、Safari 6
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
if(!isset($HTTP_RAW_POST_DATA)) {
echo "The Application could not be sent. Please save the PDF and email it manually.";
exit;
}
$email_from = "xxx@xxx.com";
$email_subject = "Subject";
$email_txt = "A Form has been sent from xxx.com. See
attachment.";
$email_to = "xxx@xxxxx.com";
$headers = "From: ".$email_from;
$semi_rand = md5(time());
$mime_boundary = "----=_NextPart_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n"
.$email_txt. "\n\n";
// This uses the function above as the Version of PHP on the server
//does not have
// it available.
$pdf = $HTTP_RAW_POST_DATA;
$data = chunk_split($pdf);
$email_message .= "--{$mime_boundary}\n" .
"Content-type: application/pdf;\n name=\"App.pdf\"\n" .
"Content-Transfer-Encoding: quoted-printable\n" .
"Content-Disposition: attachment;\n filename=\"App.pdf\"\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo ("The file was successfully sent!");
} else {
die("Sorry but the email could not be sent. Please go back and try
again!");
}
?>