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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.