【问题标题】:Sending email filled PDF form发送电子邮件填写的 PDF 表格
【发布时间】:2011-11-08 16:00:45
【问题描述】:

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

【问题讨论】:

  • 对不起,我不明白你的问题。你说的表格是pdf表格吗?它是一个网站吗?你试过什么?你在服务器上吗? Windows、Linux、Mac 还是其他?
  • 网站上的PDF格式。用户将填写表格并点击提交。
  • 什么网络环境(asp.net 或其他)?您可以访问邮件服务器 (smtp) 吗?到目前为止,您尝试了什么?
  • Web 环境是 PHP。是的,我们可以访问邮件服务器(smtp)。我正在尝试使用 Javascript。如果我需要任何服务器脚本或其他东西,请告诉我。

标签: php javascript forms email pdf


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

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

    最后一件事是在此 php 代码所在的根目录中创建一个名为 pdfs 的文件夹。 (所以如果你把 php 放在一个名为 email 的文件夹中,那么在 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!"); 
    } 
    

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 2020-05-20
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      相关资源
      最近更新 更多