[英]How to send fillable pdf (filled with pdftk) via PHPMailer?
I have a form on a website that customers fill.我在客户填写的网站上有一个表格。 When user filles the form and clicks submit data is sent to a pdf(invoice) I've already created and certain spots in pdf are filled with that data.当用户填写表格并点击提交时,数据将发送到我已经创建的 pdf(发票),并且 pdf 中的某些位置已填充该数据。 I did this using PDFTK library:我使用 PDFTK 库做到了这一点:
public function generate($data)
{
$filename = date("d-m-Y-His") . ".pdf";
$pdf = new Pdf('./form.pdf');
$pdf->fillForm($data)
->flatten()
->saveAs('./completed/' . $filename);
$path = './completed/' .$filename;
return $path;
}
The problem is, i dont know how to send this filled pdf via PHPMailer library, as pdf is recquired to be a string in order to work with phpmailer.问题是,我不知道如何通过 PHPMailer 库发送这个填充的 pdf,因为 pdf 需要是一个字符串才能与 phpmailer 一起使用。
$pdf = new GeneratePDF;
$response = $pdf->generate($data);
$email = new PHPMailer();
$email->SetFrom('you@example.com', 'Your Name');
$email->Subject = 'Test';
$email->Body = 'Test';
$email->AddAddress( 'mail exmp' );
$email->AddAttachment( $response , 'NameOfFile.pdf' );
$email->Send();
And how to actually save file in cpanel server, as when i do this it doesnt work on a server.以及如何在 cpanel 服务器中实际保存文件,因为当我这样做时它在服务器上不起作用。
pdf is recquired to be a string in order to work with phpmailer pdf 必须是一个字符串才能与 phpmailer 一起使用
This is not true.这不是真的。 addAttachment()
requires that you pass in a path to a local file on disk, so you could do: addAttachment()
要求您将路径传递到磁盘上的本地文件,因此您可以执行以下操作:
$email->addAttachment(generate(), 'NameOfFile.pdf');
You can pass in a binary string using addStringAttachment()
, but that's not what you're asking for here.您可以使用addStringAttachment()
传入二进制字符串,但这不是您在这里要求的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.