Jump to content

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


mattclements

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

Link to comment
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.

 

Link to comment
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
?>

Link to comment
Share on other sites

  • 1 month later...
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.