Submission form that generates a PDF and then emails it

I have to come up with a way to allow co-workers to fill in an HTML form and upon clicking the submit button, have the script convert the form data into a PDF and then have it attached to an email and sent to a specified email address.

Has anyone come across a script that does this, or does part of this? I’d like to see if it’s possible to modify an existing script if possible.

Thanks in advance.

Never tried it but it looks like it should work fine:


Use FPDF. It’s quite powerful but has it’s pros and cons. I’ve used it for generating PDF’s on the fly from scanning web pages screen shots. Quality was so-so but if what you want to do is simple reporting or something it should work just fine.

Here’s what I’m trying to do - I’ve created an HTML form with about 15-20 fields, most are text fields, a few are check boxes. Upon submission of this form, I’d like the form data to be compiled into an automatically-generated PDF that is then automatically sent to a specified email address as an attachment. What I really need is a primer on the functionality and a few specific questions answered. I’m a beginner PHP developer with a solid understanding of HTML. I’m usually pretty good at piecing scripts together and modifying existing PHP scripts rather than writing them from scratch.

I’ve found some code snippets (referenced in links below) and a couple of relevant discussions on this topic here on Experts Exchange, etc.

I’m trying to use this code as a starting point for the processing script:

From what I’m gathering, there are 3 parts to the functionality of the script I referenced above and how it would relate to my application - the HTML form, the script that processes the PDF and mails it, and the FPFD script ( that actually creates the PDF and is referenced in the processing script. The FPDF script makes it possible to create the PDF on the fly - which I’ve uploaded to the server. But I’m not exactly sure how to make it all work (that is, how is the script initiated), or how I would make it work for what I need.

First off, I haven’t even been able to make it work as is, without the HTML form aspect. I placed that code in a file, changed the email from/to addresses and then I point my browser to that file and hit enter. Nothing happens - no page loads, no email gets sent, no PDF gets generated. The same thing happens in both IE and Firefox, a blank page. Am I doing something wrong or is the script just not working?

Now, to make it work for my application (using HTML form data), would I edit my form tag in my HTML form and have it call the processing script to initiate the script? In the processing script, would I swap out this line:
$pdf->Cell(40,10, “this is a pdf example”);

for code like this:
$pdf->Cell(40,10, $_POST[‘name’]);
$pdf->Cell(40,10, $_POST[‘address’]);
$pdf->Cell(40,10, $_POST[‘phone’]);
$pdf->Cell(40,10, $_POST[‘etc’]);

and then repeat that for all of my form fields? What would the code look like for the check box field data? I’ve read the FPDF tutorials and it doesn’t appear to touch on form data.

I’ve also tried to achieve my goals with a different script with no success:

I’ve created the PDF form and am getting the script to output the fields in the browser, but not into the PDF template form I created and I also cannot get it to send email, let alone attach the PDF in the email. I have other form-mail scripts working fine on the server so I know that the PHP mail tool is not the issue. I’m assuming I need to change the following line (45) in the submit_form.php file from:
require_once ‘createFDF.php’;

require_once ‘process-xfdf.php’;

in order to use the function that sends the PDF instead of just outputting it to the browser.

Part of the problem is that since I’m not an advanced coder, I’m not sure which parts of these scripts require configuration for my application and which parts can be left alone. The script mentioned just above looks like it will do exactly what I need without the use of FPDF, but it’s got multiple output possibilities and does not explain in much detail how to get it configured to attach the PDF to an email as opposed to just outputting it to the browser - which script files I need to reference, which lines of code should be removed/edited, etc.

Please assume I know very little about PHP coding when explaining any points. Thanks in advance for any help. It’s greatly appreciated.

*** Edit ****

Just an update - I found a space in this line of code in the first script solution I referred to above:
$pdf->Cell(40,10, “this is a pdf example”);

I removed the space in between the comma and the quote and am reloaded the page in a browser and it now opens Adobe Acrobat (version 8) but I am getting now the following error:

File does not begin with “&PDF-”

I did some quick searches and found some data on this error. I’m able to open other PDF docs so I’m guessing this is related to the script, not the Adobe software, the browser, or the server.