Jump to content
#StayAtHome ×

Archived

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

mattclements

[SOLVED] Email PDF's - "On The Fly"

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
<?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
?>

Share this post


Link to post
Share on other sites

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