发送电子邮件填写PDF表格

Sending email filled PDF form

本文关键字:PDF 表格 电子邮件      更新时间:2023-09-26

我想在点击提交按钮后通过电子邮件发送填好的表单,而不提示outlook或任何邮件。怎么能做到呢?

您的表单可以提交到您网站上的URL。该URL上的脚本可以捕获表单内容,并使用SMTP服务器将其发送出去。这与使用HTML表单没有什么不同,有些人喜欢PDF表单。PDF格式的表格可以下载、填写、打印,然后手工或邮寄。

我创建了PDF表单并添加了一个提交表单的按钮。在这个提交表单的操作中,我告诉它PDF完整的文档。

然后给它一个php页面的URL链接,比如mail_my_form.php

然后创建一个PHP表单,并将其命名为mail_my_form.php。

最后一件事是在php代码所在的根目录下创建一个名为pdfs的文件夹。(如果你把php文件放在email文件夹中,那么在email文件夹中,你需要另一个名为pdf的文件夹)

现在这个脚本做的是:

  • 保存PDF文件到文件名PDF。
  • 然后将文件附加到电子邮件并发送。
  • 然后从文件夹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!"); 
}