Mail函数发送附件
2018-11-28 本文已影响0人
IARNO
<?php
$from = "xxx@qq.com";
$to = "xxx@163.com";
$subject = "标题";
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
$path = "附件路径";
$attach_filename = "附件名";
$emailBody = "请查看附件";
# 然后我们要作为附件的HTML文件
$attachment = file_get_contents($path);
$boundary = uniqid("");
$headers = "From: $from
To: $to
Content-type: multipart/mixed; boundary=\"$boundary\"";
$emailBody = "--$boundary
Content-type: text/plain; charset=utf-8
Content-transfer-encoding: 8bit
$emailBody
--$boundary
Content-type: text/html; name=$attach_filename
Content-disposition: inline; filename=$attach_filename
Content-transfer-encoding: 8bit
$attachment
--$boundary--";
mail("xxx@qq.com", $subject, $emailBody, $headers);