douzhanrun0497 2017-02-24 05:04
浏览 67

如何同时生成并通过电子邮件发送使用DOMPDF生成的PDF?

I have a problem using the DOMPDF library to generate a pdf and at the same time send it by mail.

What I need is that the moment you click on a button in html is generated and sent the pdf file at the same time; So far only send me the mail with a pdf already generated, but I need the pdf to be generated and sent. The data is collected first in a database and then the pdf is generated with the most recent record in the database.

I hope someone can help me.

Thank you

Note: without using frameworks

  • 写回答

2条回答 默认 最新

  • dongshou9878 2017-02-24 07:20
    关注

    You'll have to use either the built-in SMTP functions of PHP or use a library such as PHPMailer (not a framework)

    Once your PDF is generated, save it somewhere on the server, hold on to the full path to the PDF file and call a mail script to send the mail with an attachment (the attachment being the PDF)

    Using PHP Mailer it could look something like this:

    $mail = new PHPMailer;
    $mail->addAddress('your_email@example.com');
    $mail->addAttachment('/path/to/your/file.pdf', 'name as shown in the email.pdf');
    $mail->send();
    

    Of course you'd have to configure your mail with the host from where it will be sent, authenticate etc... but that wasn't what you asked for.

    Just replace /path/to/your/file.pdf with whatever the path is + filename of your PDF file (on the server) and replace name as shown in the email.pdf with the name you want the receiver of the email to see, for example 'invoice.pdf'

    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接