附件文件ATT00001.txt

时间:2017-04-20 11:33:50

标签: php email email-attachments

你可以帮我解决这个问题吗? 当我发送电子邮件时,我会收到我的附件,但附带一份名为ATT00001.txt的附件

// boundary 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

// header for attachment 
$header.= "\nMIME-Version: 1.0\n"."Content-Type: multipart/mixed;\n"." boundary=\"{$mime_boundary}\""; 

// multipart boundary 
$message = "This is a multi-part message in MIME format.\n\n"."--{$mime_boundary}\n"."Content-Type: text/html; charset=\"UTF-8\"\n"."Content-Transfer-Encoding: 8bit\n\n".$message."\n\n"; 
$message.= "--{$mime_boundary}\n";


  //Ajout des pieces jointes si il y en a
  if(!empty($attach)){
    foreach($attach as $pj){
      $file = fopen($pj,"rb");
      $data = fread($file,filesize($pj));
      fclose($file);
      $data = chunk_split(base64_encode($data));
      $fileName = basename($pj);
      $message.= "Content-Type: {\"application/octet-stream\"};\n"." name=\"$pj\"\n"."Content-Disposition: attachment;\n"." filename=\"$fileName\"\n"."Content-Transfer-Encoding: base64\n\n".$data."\n\n";
      $message.= "--{$mime_boundary}\n";    
    }
  }

0 个答案:

没有答案