Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:29:40+00:00 2026-06-08T17:29:40+00:00

I have a filled PDF file that when submitted sends the completed pdf, via

  • 0

I have a filled PDF file that when submitted sends the completed pdf, via the send completed pdf option in Adobe Acrobat X to th processpdf.php file (see code below) the code gets the raw data with $HTTP_RAW_POST_DATA and e-mails it. It e-mails fine, I get the pdf, but the PDF won’t open in chrome/acrobat or anything because it says it is corrupted. What am I doing wrong here??

I’m using PHP5,
Adobe Acrobat X,
Safari 6

   <?php
    error_reporting(E_ALL);
    ini_set("display_errors", 1);

    if(!isset($HTTP_RAW_POST_DATA)) {
        echo "The Application could not be sent. Please save the PDF and email it manually.";
        exit;
    }

    $email_from = "xxx@xxx.com";
    $email_subject = "Subject";
    $email_txt = "A Form has been sent from xxx.com. See
    attachment.";

    $email_to = "xxx@xxxxx.com";

    $headers = "From: ".$email_from;

    $semi_rand = md5(time());
    $mime_boundary = "----=_NextPart_x{$semi_rand}x";

    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";

    $email_message = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type:text/plain; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n"
    .$email_txt. "\n\n";

    // This uses the function above as the Version of PHP on the server
    //does not have
    // it available.

    $pdf = $HTTP_RAW_POST_DATA;

    $data = chunk_split($pdf);

    $email_message .= "--{$mime_boundary}\n" .
    "Content-type: application/pdf;\n name=\"App.pdf\"\n" .
    "Content-Transfer-Encoding: quoted-printable\n" .
    "Content-Disposition: attachment;\n filename=\"App.pdf\"\n\n" .
    $data . "\n\n" .
    "--{$mime_boundary}--\n";

    $ok = mail($email_to, $email_subject, $email_message, $headers);

    if($ok) {
    echo ("The file was successfully sent!");
    } else {
    die("Sorry but the email could not be sent. Please go back and try
    again!");
    }
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:29:41+00:00Added an answer on June 8, 2026 at 5:29 pm

    I got it working!! Thank you for the suggestion of phpmailer that seems to have solved the issue.

    Working code. Hope this helps people out there from the 8+ hours I spent trying to solve this issue! I can’t believe how little documentation there is about handling fillable PDF’s with PHP. Use the PHPmailer class and the below code

    <?php
    if(!isset($HTTP_RAW_POST_DATA)) {
        echo "The Application could not be sent. Please save the PDF and email it manually.";
        exit;
    }
    echo "<html><head></head><body><img src='loading.gif'>"; //Loading image
    
    //Create PDF file with the filled data
    $semi_rand = md5(time());
    $pdf = $HTTP_RAW_POST_DATA;
    
     $file = $semi_rand . ".pdf"; 
     $handle = fopen($file, 'w+');
     fwrite($handle, $pdf);   
     fclose($handle);
    //
    
    require_once('class.phpmailer.php');
    
    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
    
    $mail->IsSMTP(); // telling the class to use SMTP
    
    try {
      $mail->Host       = "mail.xxxxx.com"; // SMTP server
      $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
      $mail->SMTPAuth   = true;                  // enable SMTP authentication
      $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
      $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
      $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
      $mail->Username   = "XXXX@XXXXXX.com";     // GMAIL username
      $mail->Password   = "XXXXX";               // GMAIL password
      $mail->AddAddress('XXXX@XXXX.com', 'First last');
      $mail->SetFrom('XXXX@XXXXXX.com', 'Application ');
      $mail->Subject = 'Subject';
      $mail->Body = 'Body of the e-mail';
      $mail->AddAttachment($file); // attachment
      ob_start(); $mail->Send(); ob_get_clean(); //Prevents SMTP responses
    
      unlink($file);  //delete the temporary pdf file then redirect to the success page
      echo '<META HTTP-EQUIV="Refresh" Content="0; URL=success.php">';    
      exit; 
    
    //otherwise show errors
    } catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
    }
      unlink($file);  //doubley make sure the temp pdf gets deleted
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PDF document that represents a print form that is normally filled
I have a datagrid that I have filled with data from a sql database.
I've created an app which contains form and that have to filled up in
I have dynamic array filled with bytes, which are read from .raw file with
We have created a servlet that provides a FDF file for our clients. The
I have a PDF reader that displays pages of the document. What I want
Importing a spreadsheet I have filled a DataTable object with that data and returns
I have a WSGI application that generates invoices and stores them as PDF. So
I have a bunch of PDF files that I receive once a week. Some
Here is what I did: 1. I have a template WORD file that can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.