如何生成多个 PDF 并使用 PHP 通过电子邮件附件发送?
How to generate more than one PDF and send through email attachment using PHP?
如何生成多个 pdf 并通过电子邮件附件发送?
我正在使用 fpdf php 库生成 pdf 并希望通过电子邮件发送多个 pdf 附件。所以我试过,
<?php
require('fpdf.php');
// Generate first One.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('.assets/temp/download1.pdf','f');
$file1='.assets/temp/download1.pdf';
// Generate Second PDF.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('.assets/temp/download2.pdf','f');
$file2='.assets/temp/download2.pdf';
// use phpmailer to send email.
// load attachments and messages.
// send
// unset files.
?>
这将产生错误消息:FPDF 错误:文档已关闭。因为我无法在没有关闭文档的情况下加载两次。所以请问我通过附件发送多个 pdf 的解决方案。
尝试使用 'S' 参数代替 'F'
$pdf1 = new FPDF();
$pdf1->AddPage();
$pdf1->SetFont('Arial', 'B', 16);
$pdf1->Cell(40, 10, 'Hello World1!');
$file1 = ".assets/temp/download1.pdf";
$pdf1content = $pdf1->Output('S');
file_put_contents($file1, $pdf1content);
$pdf2 = new FPDF();
$pdf2->AddPage();
$pdf2->SetFont('Arial', 'B', 16);
$pdf2->Cell(40, 10, 'Hello World2!');
/**/
$file2 = ".assets/temp/download2.pdf";
$pdf2content = $pdf2->Output('S');
file_put_contents($file2, $pdf2content);
// use phpmailer to send email.
// load attachments and messages.
// send unset files.
如何生成多个 pdf 并通过电子邮件附件发送?
我正在使用 fpdf php 库生成 pdf 并希望通过电子邮件发送多个 pdf 附件。所以我试过,
<?php
require('fpdf.php');
// Generate first One.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('.assets/temp/download1.pdf','f');
$file1='.assets/temp/download1.pdf';
// Generate Second PDF.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('.assets/temp/download2.pdf','f');
$file2='.assets/temp/download2.pdf';
// use phpmailer to send email.
// load attachments and messages.
// send
// unset files.
?>
这将产生错误消息:FPDF 错误:文档已关闭。因为我无法在没有关闭文档的情况下加载两次。所以请问我通过附件发送多个 pdf 的解决方案。
尝试使用 'S' 参数代替 'F'
$pdf1 = new FPDF();
$pdf1->AddPage();
$pdf1->SetFont('Arial', 'B', 16);
$pdf1->Cell(40, 10, 'Hello World1!');
$file1 = ".assets/temp/download1.pdf";
$pdf1content = $pdf1->Output('S');
file_put_contents($file1, $pdf1content);
$pdf2 = new FPDF();
$pdf2->AddPage();
$pdf2->SetFont('Arial', 'B', 16);
$pdf2->Cell(40, 10, 'Hello World2!');
/**/
$file2 = ".assets/temp/download2.pdf";
$pdf2content = $pdf2->Output('S');
file_put_contents($file2, $pdf2content);
// use phpmailer to send email.
// load attachments and messages.
// send unset files.