发送电子邮件填写的PDF表单

时间:2011-09-01 19:07:49

标签: php javascript forms email pdf

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

2 个答案:

答案 0 :(得分:0)

您的表单可以提交到您网站上的网址。该URL上的脚本可以捕获表单内容并使用SMTP服务器将其邮寄出去。它与使用HTML表单没有什么不同,有些人喜欢PDF表单。 PDF表格可以下载,填写,打印,然后手动或通过蜗牛邮件提供。

答案 1 :(得分:0)

我创建了PDF表单并添加了一个按钮,然后提交表单。在这份提交表格的行动中,我告诉它PDF格式的完整文件。

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

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

最后一件事是在这个PHP代码的根目录中创建一个名为pdfs的文件夹。 (因此,如果您将php放在名为email的文件夹中,那么在电子邮件文件夹中,您需要另一个名为pdfs的文件夹。)

现在这个脚本的作用是:

  • 将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!"); 
} 
相关问题