【问题标题】:Fill php form --> upload file ---> send mail with attachment [closed]填写php表单->上传文件->发送带有附件的邮件[关闭]
【发布时间】:2012-11-25 17:14:43
【问题描述】:

我知道这个问题被问了好几次,但我没有找到有效的答案。

正如标题所说,我有一个输入文件类型的 php 表单,在提交时,所有数据都将通过电子邮件发送,包括作为附件的文件,为什么我找不到任何工作脚本。

请帮忙。

更新我的答案

$fileatt  = $_FILES['uploadfile']['tmp_name'];
$fileatt_type = $_FILES['uploadfile']['type'];
$fileatt_name = $_FILES['uploadfile']['name'];


$subject = "Some Subject goes here";
$uploadedfile = $_FILES['uploadfile']['name'];
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$headers .= "Content-Type: application/octet-stream; name=\"".$fileatt_name."\"\r\n";
$headers .=  "Content-Transfer-Encoding: base64\r\n";




    // create a boundary string. It must be unique
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

      // Add the headers for a file attachment
      $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed;\n" .
                  " boundary=\"{$mime_boundary}\"";

     if (is_uploaded_file($fileatt)) {
      // Read the file to be attached ('rb' = read binary)
      $file = fopen($fileatt,'rb');
      $data = fread($file,filesize($fileatt));
      fclose($file);

      // Base64 encode the file data
      $data = chunk_split(base64_encode($data));  
     }
//begin of HTML message 
$message ="This is a multi-part message in MIME format.\n\n";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$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";

【问题讨论】:

标签: php file-upload email-attachments


【解决方案1】:

你没有找到它,因为你没有很好地搜索。
来,学习本教程:

-填写表格并使用此上传文件: http://www.9lessons.info/2012/04/file-upload-progress-bar-with-jquery.html
- 使用phpmailer 添加附件:phpMailer attachment

【讨论】:

  • 感谢您的回复,但显然您没有很好地阅读我的问题。
  • @Digitalfortress : 我刚刚改了答案
  • 我想我必须使用 phpMailer,php 邮件不起作用谢谢
  • 它适用于 gr8。问题可能是 smtp 设置。至于邮件附件,给出问题的链接。
猜你喜欢
  • 2015-03-13
  • 1970-01-01
  • 1970-01-01
  • 2013-06-25
  • 2020-01-04
  • 2017-09-06
  • 2012-09-09
  • 2012-09-28
  • 1970-01-01
相关资源
最近更新 更多