mattclements Posted September 14, 2009 Share Posted September 14, 2009 Hey all! I am using PDF Libs to auto generate PDF Invoices - at the moment I can download these manually as the code has: //Close Page PDF_end_page($mypdf); PDF_close($mypdf); //Buffer & Display Page $mybuf = PDF_get_buffer($mypdf); $mylen = strlen($mybuf); header("Content-type: application/pdf"); header("Content-Length: $mylen"); header("Content-Disposition: inline; filename=gen01.pdf"); print $mybuf; PDF_delete($mypdf); This asks the user to download the file. However I am now trying to get the script to add this file to an email as an attachment serverside (using PHP) and email clients their invoices. Any ideas? PDFLibs, PHP 5, MySQL 5, FC4 Regards, Matt Quote Link to comment Share on other sites More sharing options...
Perfidus Posted September 15, 2009 Share Posted September 15, 2009 There are several approach to this problem: - Will you keep those PDF or just genewrate them from DDBB in the moment of being sent? - If u r not gonna keep them u should store them in a temp file to attach them to the mail. - If u r gonna keep them as pdf files u rather send a link to the file. Quote Link to comment Share on other sites More sharing options...
mattclements Posted September 15, 2009 Author Share Posted September 15, 2009 I won't keep these files - generate them on the fly & email - i can get it to attach a tempory file no problem - but how do i get it to save it automatically? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 15, 2009 Share Posted September 15, 2009 <?php //Close Page PDF_end_page($mypdf); PDF_close($mypdf); //Buffer & Display Page $mybuf = PDF_get_buffer($mypdf); //Removed as it for download only /* $mylen = strlen($mybuf); header("Content-type: application/pdf"); header("Content-Length: $mylen"); header("Content-Disposition: inline; filename=gen01.pdf"); */ PDF_delete($mypdf); $pdffile = tempnam("/tmp", "PDF"); //create temp file $handle = fopen($pdffile, "w"); //open temp file fwrite($handle, $mybuf); //write pdf data to temp fclose($handle); //close temp //Email file here $pdffile /*add email code here*/ unlink($pdffile); //remove temp file ?> Quote Link to comment Share on other sites More sharing options...
mattclements Posted September 16, 2009 Author Share Posted September 16, 2009 Thank you so much! Brilliant! Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted October 24, 2009 Share Posted October 24, 2009 tell me how to attach to an email Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.