Link to home
Start Free TrialLog in
Avatar of CenturyRow
CenturyRowFlag for United States of America

asked on

PHP script to email FDF data

Can someone point me to a PHP script to email to a single email address FDF data generated by an on-line pdf form?  The PHP script needs to operate on a Debian Linux server, which has sendmail loaded.
Avatar of nasirbest
nasirbest
Flag of Pakistan image

use following code just remember to adjust pdf , and html, text templates path
$company_name = "My Company";
$company_email = "mail@company.my";
$user_email = "user@company.com";
$subject = "Customer Email";

$random_hash = md5(uniqid(time()));
$attachment = chunk_split(base64_encode(file_get_contents("/tmp/my.pdf")));

$body_email_text="path/to/body_email.txt.php";
ob_start();
include($body_email_text);
$txt_message = ob_get_clean();

$body_email_template="path/to/body_email.tpl.php";
ob_start();
include($body_email_template);
$html_message = ob_get_clean();

$header  = "From: $company_name <$company_email>\r\n";
$header .= "Reply-To: $company_email\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"mixed$random_hash\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--mixed$random_hash\r\n";

$header .= "Content-Type: multipart/alternative; boundary=\"alt$random_hash\"\r\n\r\n";
$header .= "--alt$random_hash\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $txt_message."\r\n\r\n";
$header .= "--alt$random_hash\r\n";
$header .= "Content-type:text/html; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $html_message."\r\n\r\n";
$header .= "--alt$random_hash--\r\n\r\n";

$header .= "--mixed$random_hash\r\n";
$header .= "Content-Type: application/pdf; name=\"invoice.pdf\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"invoice.pdf\"\r\n\r\n";
$header .= $attachment."\r\n\r\n";
$header .= "--mixed$random_hash--";

mail($user_email, $subject, '', $header);

Open in new window

a simple text template can be
Dear Username, 

Welcome

-------------------------
The <?php echo $company_name; ?> Team

and following is a html email tempalte

<p>
Dear User, 
</p>
<p>
Welcome. 
</p>

<p>
-------------------------<br />
The <?php echo $company_name; ?> Team<br />
</p>

Open in new window

Avatar of CenturyRow

ASKER

I am sorry.  Perhaps, I wasn't clear.  I have on-line an Adobe Acrobat pdf form.  When the form is completed and it  submit button pressed, the form generates fdf data.  I need a PHP script to capture that data and email it to a single email address.  I can then enter the URL were the php file is located on my server in the pdf form.
ASKER CERTIFIED SOLUTION
Avatar of nasirbest
nasirbest
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.