我用下面的代码发送带附件的邮件<?php 
//获得表单信息
$from = $_POST['from'];
$to = $_POST['to']; 
$subject = $_POST['subject']; 
$body = $_POST['body']; 
// 定义分界线 
$boundary = "345894369383";  //分界线是一串无规律的字符
//设置header
$header = "Content-type: multipart/mixed; boundary= $boundary\r\n"; 
$header .= "From:$from\r\n"; 
//获得上传文件的文件内容
$file = $_FILES['upload_file']['tmp_name']; 
//确定上传文件的MIME类型 
$mimeType = $_FILES['upload_file']['type']; 
//获得上传文件的文件名 
$fileName = $_FILES['upload_file']['name']; 
//读取上传文件 
$fp = fopen($file, "r");  //打开文件
$read = fread($fp, filesize($file));  //读入文件
$read = base64_encode($read);  //base64编码 
$read = chunk_split($read);  //切割字符串
//建立邮件的主体,分为邮件内容和附件内容两部分
$body = "--$boundary 
Content-type: text/plain; charset=iso-8859-1 
Content-transfer-encoding: 8bit 
$body 
--$boundary 
Content-type: $mimeType; name=$fileName 
Content-disposition: attachment; filename=$fileName 
Content-transfer-encoding: base64 
$read 
--$boundary--"; 
//发送邮件 并输出是否发送成功的信息
if(mail($to, $subject,$body,$header)) 
{
echo "信件发送成功"; 
}
else 
{
echo "信件发送失败"; 
}
?> 
出来的结果如下所示Return-Path:
Date: Mon, 22 May 2000 19:17:29 +0000
From: Someone
To: Person
Message-id: <[email protected]>
Content-type: multipart/mixed; boundary="396d983d6b89a"
Subject: Here's the subject
--396d983d6b89a
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bitThis is the body of the email.--396d983d6b89a
Content-type: text/html; name=attachment.html
Content-disposition: inline; filename=attachment.html
Content-transfer-encoding: 8bit 请问我添加的附件为什么没有附件的图标然后内容也被加工后打印出来了呢,谢谢大家了