我正在使用fPDF生成预订门票。但是当我使用PHPmailer插件附加文件时。我收到一个“.dat”文件。
如何准确获取由fPDF生成的pdf文件..
感谢
以下BTW是我的代码。
$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();
答案 0 :(得分:0)
此代码现在有效, 在给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();