您可以尝试使用以下代码:
$filename = \'myfile\';
$path = \'your path goes here\';
$file = $path . \"/\" . $filename;
$mailto = \'mail@mail.com\';
$subject = \'Subject\';
$message = \'My message\';
$content = file_get_contents($file);
$content = chunk_split( 64_encode($content));
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (RFC)
$eol = \"\\r\\n\";
// main header (multipart mandatory)
$headers = \"From: name <test@test.com>\" . $eol;
$headers .= \"MIME-Version: 1.0\" . $eol;
$headers .= \"Content-Type: multipart/mixed; boundary=\\\"\" . $separator . \"\\\"\" . $eol;
$headers .= \"Content-Transfer-Encoding: 7bit\" . $eol;
$headers .= \"This is a MIME encoded message.\" . $eol;
// message
$body = \"--\" . $separator . $eol;
$body .= \"Content-Type: text/plain; charset=\\\"iso-8859-1\\\"\" . $eol;
$body .= \"Content-Transfer-Encoding: 8bit\" . $eol;
$body .= $message . $eol;
// attachment
$body .= \"--\" . $separator . $eol;
$body .= \"Content-Type: application/octet-stream; name=\\\"\" . $filename . \"\\\"\" . $eol;
$body .= \"Content-Transfer-Encoding: 64\" . $eol;
$body .= \"Content-Disposition: attachment\" . $eol;
$body .= $content . $eol;
$body .= \"--\" . $separator . \"--\";
//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
echo \"mail send ... OK\"; // or use booleans here
} else {
echo \"mail send ... ERROR!\";
print_r( error_get_last() );
} 继续阅读与本文标签相同的文章
上一篇 :
Windows未来成谜 微软的现代OS究竟是啥?
下一篇 :
php多维数组转化为一维数组的几种方法
-
特斯拉交付量未达预期,今年股价已下跌27%!上海新厂成了新希望
2026-05-15栏目: 教程
-
中国工业互联网安全保障体系初步建成
2026-05-15栏目: 教程
-
Word里面如何设置行距
2026-05-15栏目: 教程
-
Ubuntu19.10正式版发布,搭载GNOME 3.34
2026-05-15栏目: 教程
-
歌尔创客闪耀航模大会 Wemake提升荣成文旅内涵
2026-05-15栏目: 教程
