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
https://forums.phpfreaks.com/topic/174259-solved-email-pdfs-on-the-fly/
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.

 

<?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
?>

  • 1 month later...

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.