FPDF 在作为附件发送时生成一个“.dat”文件

FPDF generates a ".dat" file when sending as attachment

我正在使用 fPDF 生成用于预订的机票。但是,当我使用 PHPmailer 插件附加文件时。我收到一个“.dat”文件。

如何准确获取由 fPDF 生成的 pdf 文件..

谢谢

顺便说一句,下面是我的代码。

 $pdf_filename = tempnam(sys_get_temp_dir(), "pdf");
 $pdf = new PDF();
 $pdf->AliasNbPages();
 $pdf->AddPage();
 $pdf->Ln(5);
 $pdf->Cell(10);
 $pdf->SetFont('Times','B',10);
 $pdf->Cell(45,5,"Project Reference Number:",0,0,'L');
 $pdf->SetFont('Times','',10);
 $pdf->Cell(45,5,"$refno",0,0,'L');
 $pdf->SetFont('Times','B',10);
 $pdf->Cell(45,5,"Date Booked:",0,0,'R');
 $pdf->SetFont('Times','',10);
 $pdf->Cell(35,5,"$datetoday",0,0,'R');  
 .
 .
 .
 .                                                     
 $pdf->Cell(10);
 $pdf->SetFont('Times','B',9);
 $pdf->SetTextColor(255,0,0);
 $pdf->MultiCell(170,5,"$remarks",1,'L',0);
 $pdf->SetTextColor(0,0,0);

 $pdf->Output();
 $pdf->Output($pdf_filename,"F");
 $pdfpath = $pdf_filename;




                                                    //send mail to
  require 'phpmailer/PHPMailerAutoload.php';

  $mail = new PHPMailer;
  $mail->Host = 'smtp.gmail.com'; //smtp2.example.com';
  $mail->SMTPAuth = true;                               
  $mail->Username = 'email@gmail.com';              
  $mail->Password = 'password';                    
  $mail->SMTPSecure = 'ssl';                           
  $mail->Port = 465;                                   
  $mail->From = 'site-admin@the-inspection-company.com';
  $mail->FromName = 'The Inspection Company Ltd';
  $mail->addAddress('email2@gmail.com','Receiver');  

  $qry=$handler->prepare("SELECT * FROM uploads WHERE upload_bookid = ? AND upload_compid = ?");
   $qry->execute(array($intrno,$id));
   $row = $qry->rowCount();

   while($row = $qry->fetch(PDO::FETCH_ASSOC)){
   $path = $row['upload_path'];
   $mail->addAttachment($path);        
   }

   $mail->addAttachment($pdfpath);                             
   $mail->isHTML(true);
   $mail->Subject = "TIC - New Booking Request";
   $mail->Body = "This is a test email message"
   $mail->send();

此代码现在有效, 在给 pdf 一个临时名称并生成它之后,我重命名了文件并将其附加到 phpmailer

$pdf_filename = tempnam(sys_get_temp_dir(), "pdf");
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Ln(5);
$pdf->Cell(10);
$pdf->SetFont('Times','B',10);
$pdf->Cell(45,5,"Project Reference Number:",0,0,'L');
$pdf->SetFont('Times','',10);
$pdf->Cell(45,5,"$refno",0,0,'L');
.
.
.
.                                                     
$pdf->Cell(10);
$pdf->SetFont('Times','B',9);
$pdf->SetTextColor(255,0,0);
$pdf->MultiCell(170,5,"$remarks",1,'L',0);
$pdf->SetTextColor(0,0,0);
$pdf_filename.='.pdf';
$pdf->Output();
$pdf->Output($pdf_filename,"F");
$pdfpath = $pdf_filename;




  //send mail to
 require 'phpmailer/PHPMailerAutoload.php';

 $mail = new PHPMailer;
 $mail->Host = 'smtp.gmail.com'; //smtp2.example.com';
 $mail->SMTPAuth = true;                               
 $mail->Username = 'email@gmail.com';              
 $mail->Password = 'password';                    
 $mail->SMTPSecure = 'ssl';                           
 $mail->Port = 465;                                   
 $mail->From = 'site-admin@the-inspection-company.com';
 $mail->FromName = 'The Inspection Company Ltd';
 $mail->addAddress('email2@gmail.com','Receiver');  

 $qry=$handler->prepare("SELECT * FROM uploads WHERE upload_bookid = ? AND upload_compid = ?");
 $qry->execute(array($intrno,$id));
 $row = $qry->rowCount();

 while($row = $qry->fetch(PDO::FETCH_ASSOC)){
 $path = $row['upload_path'];
 $mail->addAttachment($path);        
 }

 $mail->addAttachment($pdfpath);                             
 $mail->isHTML(true);
 $mail->Subject = "TIC - New Booking Request";
 $mail->Body = "This is a test email message"
 $mail->send();