发送电子邮件填写的PDF表格 [英] Sending email filled PDF form

查看:86
本文介绍了发送电子邮件填写的PDF表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击提交按钮后,我想通过电子邮件发送已填写的表单,而不会提示Outlook或任何邮件。怎么做?

I would like to email the filled form after submit button clicked without prompting outlook or any mail. How could it be done?

推荐答案

我创建了PDF表单,并添加了一个按钮,然后提交了表单。在此提交表单的操作中,我告诉它以PDF格式显示完整文档。

I created the PDF form and added a button which then submits form. In the actions of this submit form, I told it to PDF the complete document.

然后,我给它提供了指向php页面的URL链接,例如mail_my_form.php

Then I gave it a URL link to a php page, such as mail_my_form.php

然后我创建了一个PHP表单,并将其命名为与上面相同的名称,mail_my_form.php。

Then I created a PHP form, and named it the same as above, mail_my_form.php.

最后一个要做的是在此php代码所在的根目录中创建一个名为 pdfs 的文件夹。 (因此,如果将php放在名为email的文件夹中,然后在email文件夹中,则需要另一个名为pdfs的文件夹。)

One last thing is to create a folder called pdfs in the root of where this php code will go. (So if you put the php in a folder called email, then inside the folder of email, you need another folder called pdfs.)

现在,此脚本的作用是:

Now what this script does is:


  • 将PDF保存为文件名pdfs。

  • 然后将文件附加到电子邮件并发送。

  • 然后将其从pdfs文件夹中删除,以节省空间。 (如果需要,您也可以删除功能以将表单保存到FTP上。)

在这里。

$fileatt = date("d-m-Y-His") . ".pdf";  // Creates unique PDF name from the date 
copy('php://input',"pdfs/".$fileatt); // Copies the pdf form data to a folder named pdfs 
$fileatt = "pdfs/".$fileatt; // Path to the file gives the pdfs folder plus the unique file name we just assigned
$fileatt_type = "application/pdf"; // File Type 
$fileatt_name = "Application Form_".$fileatt.".pdf"; // Filename that will be used for the file as the attachment when it is sent

$email_from = "mywebsite"; // Who the email is from 
$email_subject = "Completed online Applications"; // The Subject of the email 
$email_message = "Please find a recent online application attached.
";
 $email_message .= "Any problems please email me...
"; // Message that the email has in it 

$email_to = "youremail@yourserver.com"; // Who the email is to 

$headers = "From: ".$email_from;

//no need to change anything else under this point

$file = fopen($fileatt,'rb'); 
$data = fread($file,filesize($fileatt)); 
fclose($file); 

$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_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/html; charset=\"iso-8859-1\"\n" . 
"Content-Transfer-Encoding: 7bit\n\n" . 
$email_message .= "\n\n"; 

$data = chunk_split(base64_encode($data)); 

$email_message .= "--{$mime_boundary}\n" . 
"Content-Type: {$fileatt_type};\n" . 
" name=\"{$fileatt_name}\"\n" . 
//"Content-Disposition: attachment;\n" . 
//" filename=\"{$fileatt_name}\"\n" . 
"Content-Transfer-Encoding: base64\n\n" . 
$data .= "\n\n" . 
"--{$mime_boundary}--\n"; 

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

if($ok) { 
unlink($fileatt); //NOW WE DELETE THE FILE FROM THE FOLDER pdfs 
Header("Location: nextpage.php"); //where do we go once the form has been submitted.

} else { 
die("Sorry but the email could not be sent. Please go back and try again!"); 
} 

这篇关于发送电子邮件填写的PDF表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆