Php FPDF电子邮件附件和outlook

Php FPDF电子邮件附件和outlook,php,pdf-generation,attachment,email-attachments,fpdf,Php,Pdf Generation,Attachment,Email Attachments,Fpdf,我正在尝试使用FPDF并将结果文件附加到电子邮件中。我看过这篇文章,在给自己发送电子邮件并在Thunderbird中查看时,给出的答案很有效。下面是给出的示例代码: <?php require('lib/fpdf/fpdf.php'); $pdf = new FPDF('P', 'pt', array(500,233)); $pdf->AddFont('Georgiai','','georgiai.php'); $pdf->AddPage(); $pdf->Imag

我正在尝试使用FPDF并将结果文件附加到电子邮件中。我看过这篇文章,在给自己发送电子邮件并在Thunderbird中查看时,给出的答案很有效。下面是给出的示例代码:

 <?php
 require('lib/fpdf/fpdf.php');

$pdf = new FPDF('P', 'pt', array(500,233));
$pdf->AddFont('Georgiai','','georgiai.php');
$pdf->AddPage();
$pdf->Image('lib/fpdf/image.jpg',0,0,500);
$pdf->SetFont('georgiai','',16);
$pdf->Cell(40,10,'Hello World!');

// email stuff (change data below)
$to = "myemail@example.com"; 
$from = "me@example.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "test.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

// main header
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message
mail($to, $subject, $body, $headers);

?>

但是,在outlook(2007)中发送和查看时,它也会将邮件创建为附件,这是与代码有关还是与outlook有关/

谢谢你的帮助


Ian

在我看来,这是一条MIME编码的消息是没有意义的。作为一部分的内容;通常,这样一句话在第一个mime分隔符之前,通知任何没有mime功能的邮件阅读器用户以下几行代表什么。本质上,您的邮件包含两个文本部分,一个是纯文本(这是MIME编码的邮件)和一个html(请参阅附件),位于多部分/混合容器中。如果它是一个多部分/备选方案,邮件阅读器会选择其中一个进行显示,但这样一来,读者可能会怀疑显示什么

因此,我建议缩短

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

$body = "This is a MIME encoded message.".$eol.$eol;