加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:38:36 所属栏目:PHP教程 来源:网络整理
导读:我通过 PHP发送电子邮件没问题.我想附加一个.csv文件以及提供的HTML电子邮件.我似乎无法找到如何做到这一点.是否有某种Content-Type I还必须包含在$headers中以及Content-Disposition of attachment? $to = 'email@email.com';$subject = 'A Subject Line';
我通过 PHP发送电子邮件没问题.我想附加一个.csv文件以及提供的HTML电子邮件.我似乎无法找到如何做到这一点.是否有某种Content-Type I还必须包含在$headers中以及Content-Disposition of attachment?
$to = 'email@email.com';
$subject = 'A Subject Line';
$headers  = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";

$message = "
<html>
<head>
  <title>List of New Price Changes</title>
</head>
<body>";

$message .="HTML table";
$message .="</body></html>";

mail($to,$subject,$message,$headers);
$fileatt_type = "text/csv";
$myfile = "myfile.csv";

        $file_size = filesize($myfile);
        $handle = fopen($myfile,"r");
        $content = fread($handle,$file_size);
        fclose($handle);

        $content = chunk_split(base64_encode($content));

        $message = "<html>
<head>
  <title>List of New Price Changes</title>
</head>
<body><table><tr><td>MAKE</td></tr></table></body></html>";

        $uid = md5(uniqid(time()));

        #$header = "From: ".$from_name." <".$from_mail.">rn";
        #$header .= "Reply-To: ".$replyto."rn";
        $header .= "MIME-Version: 1.0rn";
        $header .= "Content-Type: multipart/mixed; boundary="".$uid.""rnrn";
        $header .= "This is a multi-part message in MIME format.rn";
        $header .= "--".$uid."rn";
        $header .= "Content-type:text/html; charset=iso-8859-1rn";
        $header .= "Content-Transfer-Encoding: 7bitrnrn";
        $header .= $message."rnrn";
        $header .= "--".$uid."rn";
        $header .= "Content-Type: text/csv; name="".$myfile.""rn"; // use diff. tyoes here
        $header .= "Content-Transfer-Encoding: base64rn";
        $header .= "Content-Disposition: attachment; filename="".$myfile.""rnrn";
        $header .= $content."rnrn";
        $header .= "--".$uid."--";

mail($to,$header);

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读