Phpmailer从链接添加PDF附件 [英] Phpmailer add PDF attachment from a link

查看:82
本文介绍了Phpmailer从链接添加PDF附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPMailer发送自动电子邮件(显然是使用PHP作为编程语言). 我想添加一个使用TCPdf生成的PDF附件. 不幸的是,我无法在使用PHPMailer的php页面内生成PDF,也无法创建用于生成PDF的函数. 我只能使用链接来生成它,如下所示: www.mypage.com/app-pdf/link_generate_pdf.php?IDToGenerate=131&PDFOutput=I

I'm using PHPMailer to send automatic email (obviously using PHP as programming language). I would like to add a PDF attachment generated with TCPdf. Unfortunately I cannot generate the PDF inside the php page where I'm using PHPMailer, and I cannot create a function that generate it. I can only use a link to generate it, like this: www.mypage.com/app-pdf/link_generate_pdf.php?IDToGenerate=131&PDFOutput=I

我当时想我可以使用PDFOutput = S调用页面,并以某种方式返回" PDF文本并将其添加为附件. 否则,我可以使用PDFOutput = F调用该页面并将其保存到临时文件夹中,然后将其附加到电子邮件中.

I was thinking that I can recall the page with the PDFOutput=S and "return" in some way the text of the PDF and add it as attachment. Otherwise I can call the page with PDFOutput=F and save it to a temp folder and then attach it to the email.

问题是我不知道如何调用"页面,因为它是一个函数,并且不返回召回页面实际返回的内容.

The problem is that I don't know how to "call" a page as it were a function and return what the recalling page actually returns.

您有什么建议吗? 谢谢

Do you have some suggestion? Thank you

edit:我现在明白了这个问题!问题在于该URL仅可从验证(登录页面)访问.我以为在登录后,脚本可以自动读取页面.我该如何解决?

edit: I now understand the problem! The problem is that the URL is accessible only from autentication (login page). I thought that as I was logged in, the script was automatically capable of read the page. How can I solve this?

推荐答案

使用此方法首先将文件保存在服务器上,然后附加

Use this to save the file on the server first and then attach

file_put_contents("Tmpfile.pdf", fopen("http://example.com/file.pdf", 'r'));

附加为

 $mail->AddAttachment('path_to_pdf/Tmpfile.pdf', $name = 'Name_of_pdf_file', 
 $encoding = 'base64', $type = 'application/pdf');

希望这会有所帮助

试试看.在这里工作正常

Try this. works fine over here

file_put_contents("path_to_pdf/Tmpfile.pdf", 
file_get_contents("http://example.com/file.pdf"));

这篇关于Phpmailer从链接添加PDF附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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