Jump to content

How do I use PHP to email a PDF of the current page?


DeX

Recommended Posts

Hi guys, I'll try to explain this. I'm doing a quoting system for a building contractor and I have a dynamic purchase order created for every quote that's confirmed and it spits out all the materials they will need for each supplier. The layout of the page is exactly what I need emailed to the supplier so they can ship out the materials listed, it's your basic purchase order. I'm going to put a button on the page that sends the email to the supplier but I need to attach the purchase order displayed on the page. Preferably in PDF but it just needs to be an attached file. I know I can have the user use PRINT.... to save it as PDF and then use Outlook to email it but I'd like to automate it. Thanks.

Link to comment
Share on other sites

You might want to look into the dompdf library: http://www.digitaljunkies.ca/dompdf/

 

It takes HTML and converts it into a PDF document. I used it when making my report system at work and it has worked very well for us. You could use it to generate a temporary PDF file and then use another library like phpmailer ( http://phpmailer.worxware.com/ ) to send that temp file as an attachment.

 

It can be a bit finicky, especially if you use advanced CSS but overall it does a good job and they have a google group set up to provide support for it.

Link to comment
Share on other sites

I looked at that and it looks like it just downloads it to your local machine, it doesn't allow me to use any sort of mailer with it. I can just click PRINT... and then Save As PDF to do the same thing. Is there maybe a way to just use the PHP mail() function to mail a HTML email version of the current page?

Link to comment
Share on other sites

I looked at that and it looks like it just downloads it to your local machine, it doesn't allow me to use any sort of mailer with it. I can just click PRINT... and then Save As PDF to do the same thing. Is there maybe a way to just use the PHP mail() function to mail a HTML email version of the current page?

 

With DOMPDF what you need to do is send the output to a temp file instead of streaming it to the user (I don't recall exactly how to do that but I'm fairly certain it's possible) then email that temp file to the user. As far as I know the mail() function does not support attachments so you'd have to look into another library for email.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.