Posts: 22
Threads: 9
Joined: Mar 2009
Reputation:
1
Hi Ben,
I would like to generate on-line pdf invoice, save it to MySQL and send it by email as attachment.
1/ I am generating pdf file by FPDF, I can save it to disk or show it in a browser, but I could not save it to database.
For processing I use process.php method and Submission Pre-Parser module to generate pdf. As the file is not uploading from web form, I have added manually a Form field "attach" (Field type is set to file) and set a relevant database column to "mediumblob". My code is easy:
...
...
$_POST["attach"]=$pdf->Output('','S');
The script runs without any errors or stops, but database remains empty all the time. A also tried another method - save pdf and upload file from disc then:
$pdf->Output('test.pdf','F');
$filename = "test.pdf";
$fd = fopen ($filename, "r");
$binarydata = fread ($fd, filesize ($filename));
$_POST["fak_priloha"]=$binarydata;
The same results.
2/ Sending e-mail attachments from disc ({$attachment file="test.pdf"}) works but similar {$attachment field="attach"} does not even if I manually upload to database some binary content. I am only able to include binary data to emailĀ“s body by {$FILENAME_attach} which is worthless.
Any idea is welcome as I am absolutely stuck.
Thank you.
Posts: 2,456
Threads: 39
Joined: Dec 2008
Reputation:
6
Hey Nomad,
Regarding #1, no, you won't be able to store binary data in the database... at least I very much doubt it. Form Tools fields are text-based (MEDIUMTEXT, VARCHARS) and binary data should be stored in BLOBs. What I'd do instead is this:
1. save the file directly to a folder somewhere,
2. store the unique filename in the POST request and pass THAT to Form Tools
Unfortunately I don't think you'll be then able to attach the file to the email as an attachment... which leads us to your #2. Tricky!
Hmm.
How high a volume of form submissions are you expecting? One hack would be to always create the file with a specific filename, e.g. "myfile.pdf", and be sure to delete it when creating a new one. Then in your email template, always reference that specific filename by including it as an attachment.
Not great....
- Ben
Posts: 22
Threads: 9
Joined: Mar 2009
Reputation:
1
Hi, Ben,
thank you for your message. My idea was straight (and naive) it is time to start respecting the reality :-))
Let me summarize my final way: "How to send a personalized email attachment".
Maybe can be useful to somebody, not great, but works, any improvements are welcomed.
1/ Use Pre-Parsel module to generate your attachment (an invoice in my case).
2/ Save the file to disc, the is no way how to save it to database.
3/ You have to use general name of the file, e.g. "Invoice.pdf" not unique one, as {$attachment} command does not accept placeholder to specify the name of the attachment.
4/ If no attachment should be generated for the current form, delete older file from disc (if exists).
5/ Use placeholders to personalize your message you like, e.g.:
{if $ANSWER_send_attachment == "Yes"}
Please find enclosed invoice.
{/if}
6/ Use direct command {$attachment file="invoice.pdf"} to send the attachment.
You cannot use any "if statements" as file attachments won't work within other Smarty logic. If no file "invoice.pdf" exists, no attachment is sent, no error message.
----
Pretty dirty white men's trick, uh?
This works, but not tested in real yet, theoretically, I am afraid if I receive two or more form applications at the very same time, one could delete prepared saved file attachment BEFORE this can be emailed by other process.
Please, Ben, if you find some extra time, add using placeholders in "$attachment file" command. Using unique names of attachments will make this process much less complicated.
Posts: 2,456
Threads: 39
Joined: Dec 2008
Reputation:
6
Hey, not bad at all! Yes, it's a hack - but good thinking with the Pre-Parser module. I should have thought of that...!
And yes, I hope to work on this at some point - but not soon, I'll be frank. Lots of other stuff to get done first!
Posts: 3
Threads: 0
Joined: Sep 2013
Reputation:
0
(Aug 23rd, 2009, 11:03 PM)nomad Wrote: Hi, Ben,
thank you for your message. My idea was straight (and naive) it is time to start respecting the reality :-))
Let me summarize my final way: "How to send a personalized email attachment".
Maybe can be useful to somebody, not great, but works, any improvements are welcomed.
1/ Use Pre-Parsel module to generate your attachment (an invoice in my case).
2/ Save the file to disc, the is no way how to save it to database.
3/ You have to use general name of the file, e.g. "Invoice.pdf" not unique one, as {$attachment} command does not accept placeholder to specify the name of the attachment.
4/ If no attachment should be generated for the current form, delete older file from disc (if exists).
5/ Use placeholders to personalize your message you like, e.g.:
{if $ANSWER_send_attachment == "Yes"}
Please find enclosed invoice.
{/if}
6/ Use direct command {$attachment file="invoice.pdf"} to send the attachment.
You cannot use any "if statements" as file attachments won't work within other Smarty logic. If no file "invoice.pdf" exists, no attachment is sent, no error message.
----
Pretty dirty white men's trick, uh?
This works, but not tested in real yet, theoretically, I am afraid if I receive two or more form applications at the very same time, one could delete prepared saved file attachment BEFORE this can be emailed by other process.
Please, Ben, if you find some extra time, add using placeholders in "$attachment file" command. Using unique names of attachments will make this process much less complicated.
Hey dude! We use Fetchflow for online invoicing. Its completely free and as good as other paid solutions we tested. Has quite some traction. & I would actually recommend it.
http://www.fetchflow.com/support/questio...oices.html
|