"; //echo $body."
"; //定义分界线 $boundary=uniqid(""); //生成邮件头 $headers = "From: $from Content-type: multipart/mixed; boundary=\"$boundary\""; //确定上传文件的MIME类型,如果浏览器没有指定文件的MIME类型,我们可以把它定义为"application/unknown" if($attachment_type) $mimeType=$attachment_type; else $mimeType="application/unknown"; //确定文件名 $fileName=$attachment_name; //打开文件 echo $attachment; $fp=fopen($attachment,"r"); //把整个文件读入一个变量 $read=fread($fp,filesize($attachment)); //变量$read中保存的是包含整个文件内容的文本块,把这个文本块转换成邮件程序可以读懂的格式,用base64方法把它编码 $read=base64_encode($read); //为一个用base64方法编码的长字符串,把该字符串切成由每行76个字符组成的小块 $read=chunk_split($read); //建立邮件主体 $body = "--$boundary Content-type: text/plain; charset=GB2312 Content-transfer-encoding: 8bit $body --$boundary Content-type: $mimeType; name=$fileName Content-disposition: attachment; filename=$fileName Content-transfer-encoding: base64 $read --$boundary--"; //echo $to."
"; //echo $subject."
"; //echo $body."
"; //echo $headers."
"; if(mail($to,$subject,$body,$headers)) echo "ok"; echo ""; ?>