DOMPDF - 将创建的 PDF 附加到电子邮件 [英] DOMPDF - attach created PDF to email

查看:27
本文介绍了DOMPDF - 将创建的 PDF 附加到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 DOMPDF 将 PDF 附加到电子邮件的最简单方法是什么?

What is the easiest way to attach a PDF to an email via DOMPDF?

我正在使用的脚本的结尾(部分)如下:

The end of my script I am using (part of it) is below:

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();    
//below to save the pdf file - not needed if emailing pdf
file_put_contents('/home/ststrave/public_html/pdf/STS_Brochure.pdf', $dompdf->output());
//below to open pdf in browser - required
$dompdf->stream("STS_Brochure_".rand(10,1000).".pdf", array("Attachment" => false));
jexit();

只是为了澄清 - 这在 Joomla 中被使用.

Just for clarification - this is being used in Joomla.

欣赏使用标准 PHP 邮件功能的最简单/最快捷的方式.

Appreciate the simplest/quickest way using standard PHP mail function.

干杯;-)

推荐答案

PHP 的邮件功能没有标准"的文件附件方法.它是 SMTP 系统的一个极其准系统的接口,它迫使您自己完成所有附加文件的工作.

PHP's mail function has no "standard" file attachment method. It's an extremely barebones interface to the SMTP system that forces you to do ALL the work of attaching a file yourself.

我强烈建议使用 PHPMailerSwiftmailer 为您处理电子邮件 - 它将生成您自己的 MIME 电子邮件和插入附件(许多多行代码)的繁重工作减少到总共 5 行.

I strongly suggest using PHPMailer or Swiftmailer to do the email for you - it reduces the heavy grunt work of generating your own MIME email and inserting the attachment (many many lines of code) does to maybe 5 lines total.

请注意,它们都不会处理来自 DOMPDF 的流式 PDF.您必须将 PDF 保存到一个临时文件并附加,

Note that neither of them will handle a streamed PDF from DOMPDF. You'll have to save the PDF to a temporary file and attach that,

这篇关于DOMPDF - 将创建的 PDF 附加到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆