php发送.csv附件的html电子邮件

前端之家收集整理的这篇文章主要介绍了php发送.csv附件的html电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我通过 PHP发送电子邮件没问题.我想附加一个.csv文件以及提供的HTML电子邮件.我似乎无法找到如何做到这一点.是否有某种Content-Type I还必须包含在$headers中以及Content-Disposition of attachment?
  1. $to = 'email@email.com';
  2. $subject = 'A Subject Line';
  3. $headers = 'MIME-Version: 1.0' . "\r\n";
  4. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  5.  
  6. $message = "
  7. <html>
  8. <head>
  9. <title>List of New Price Changes</title>
  10. </head>
  11. <body>";
  12.  
  13. $message .="HTML table";
  14. $message .="</body></html>";
  15.  
  16. mail($to,$subject,$message,$headers);
  1. $fileatt_type = "text/csv";
  2. $myfile = "myfile.csv";
  3.  
  4. $file_size = filesize($myfile);
  5. $handle = fopen($myfile,"r");
  6. $content = fread($handle,$file_size);
  7. fclose($handle);
  8.  
  9. $content = chunk_split(base64_encode($content));
  10.  
  11. $message = "<html>
  12. <head>
  13. <title>List of New Price Changes</title>
  14. </head>
  15. <body><table><tr><td>MAKE</td></tr></table></body></html>";
  16.  
  17. $uid = md5(uniqid(time()));
  18.  
  19. #$header = "From: ".$from_name." <".$from_mail.">\r\n";
  20. #$header .= "Reply-To: ".$replyto."\r\n";
  21. $header .= "MIME-Version: 1.0\r\n";
  22. $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  23. $header .= "This is a multi-part message in MIME format.\r\n";
  24. $header .= "--".$uid."\r\n";
  25. $header .= "Content-type:text/html; charset=iso-8859-1\r\n";
  26. $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  27. $header .= $message."\r\n\r\n";
  28. $header .= "--".$uid."\r\n";
  29. $header .= "Content-Type: text/csv; name=\"".$myfile."\"\r\n"; // use diff. tyoes here
  30. $header .= "Content-Transfer-Encoding: base64\r\n";
  31. $header .= "Content-Disposition: attachment; filename=\"".$myfile."\"\r\n\r\n";
  32. $header .= $content."\r\n\r\n";
  33. $header .= "--".$uid."--";
  34.  
  35. mail($to,$header);

尝试根据您的情况修改代码.

猜你在找的PHP相关文章