This topic is locked

Emailing a report

6/14/2006 2:30:33 PM
PHPRunner General questions
D
Dale author

My client would like to automatically email an invoice report that I created in phprunner. I created a modified _print.php for the record. Everything displays perfectly when the user selects Print Invoice.
Is there any way that I could have a report populated with the selected data and emailed to a user.
Also I would like to be able to create email templates that could be called when printing.
Am I making sense.

example

Im looking at a customer record that has invoice records attached.

The invoice could be paid in full, 30 days outstanding, 60 days outstanding or 90+ days outstanding.

My client would like to be able to click a button Email Statement and an invoice mailed to the client with the appropriate phrases inserted for the status of the invoice.
Is this kind of thing possible?

G
gawde 6/14/2006

Hey DaleM,
I'm fairly new to this forum so it's amazing I may have an answer for an "old timer" like yourself.

Anyway, I needed this same functionality so did a little research and found an interesting set of PHP functions that operate on the HTML "output buffer". In a nutshell, you capture the generated HTML page in a buffer before it gets sent to the client. You can then place the contents of the buffer in a variable, which gets sent as the body of an email. You also "flush" the buffer so the user can see the result as well. The one possible gotcha that can occur is if you have references to local images, files or links. When the page resolves on your clients machine, it won't find them. You can either remove such items (preferably) or provide an absolute path (full domain, folder, file). A sample of the code is below:
=============================

<?php

ob_start(); // start capture of html to buffer

?>
....Your Invoice page
<?php

$page_content = ob_get_contents(); // place buffer contents in variable

ob_end_clean(); // stop buffer capture
// To send HTML mail, the Content-type header must be set

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: from_whoever <fromwhoever@domain.com.com>' . "\r\n"; //this could be done here or in the mail function itself
echo $page_content; //send page to user for viewing
mail("to_whoever@domain.com","Subject line",$page_content,$headers); // mail as html mailbody

?>
====================================
In your case the mail function would only be executed if they request it. Probably a javascript snippet needed here. Sorry. not very good at that right now. I don't know if this is the most effective way to do this, but it will give you an answer if I understood your question correctly.
Good luck.

D
Dale author 6/14/2006

Thanks Greg_de
Appreciate the suggestion. I will give that a go.