使用PHP脚本通过电子邮件发送PDF

时间:2015-11-03 19:44:09

标签: php pdf email-attachments acrobat

我已经在StackOverflow中看到了其他问题/答案,但我不能为我的生活让这个工作正常,我真的很好奇,看看我做错了什么。 / p>

保险公司拥有PDF,他们希望客户在线填写并通过他们的网站提交。 PDF表格将通过电子邮件发送,并附上所有PDF格式的附件。

我有一个发送PDF的PHP脚本,但它没有保存表单数据(名称,地址等)。它只发送空白PDF。这是代码:

<?php
$fileatt = "file-name.pdf";
$fileatt_type = "application/pdf";
$fileatt_name = "file-name.pdf";

$email_from = "From"; // Who the email is from
$email_subject = "Form"; // The Subject of the email
$email_message = "Text.";

$email_to = "someemail@gmail.com"; // Who the email is to

$headers = "De: ".$email_from;

//no need to change anything else under this point

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_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/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
    echo 'Sent...';
  //unlink($fileatt); //NOW WE DELETE THE FILE FROM THE FOLDER pdfs
}
else {
    echo 'Error...';
}
?>

我感谢任何输入/反馈。我已经考虑过使用PHPMailer,但我认为这样做了99%,我很想知道它缺少什么?

(PDF文件是使用Word创建的,然后使用Adobe Acrobat Pro创建了所有输入字段,并且创建了提交按钮,提交按钮指向发送PDF的PHP脚本)

0 个答案:

没有答案