不明白下面的 mail 功能,在本地各种格式附件都可以,
<?php
/*$to="softinfo@bbi.com.cn";
$Subject="Testmail";
$HTML="<font color=red>This is the first test in html format.</font>";
$attach="d:\\php_work\\01.doc";
$From="softinfo@bbi.com.cn";
*/
$FromName="软件资讯行";
$ATTM=array($attach);
//$ATTM=$attach;
SendMail(
$From,$FromName,$to,$Subject, $HTML,$ATTM); //body and attachment(s)
function SendMail($From,$FromName,$To,$Subject,$Html,$AttmFiles){
$OB="----=_OuterBoundary_000";
$IB="----=_InnerBoundery_001";
$Html=$Html?$Html:preg_replace("/\n/","{br}",$Text)
or die("neither text nor html part present.");
//echo $To;
$From or die("服务器邮件地址有问题,请检查服务器邮件地址或设置是否正确!");
$To or die("客户注册信息有误,邮件地址联不上!");
$headers ="MIME-Version: 1.0\r\n";
$headers.="From: ".$FromName." <".$From.">\n";
$headers.="To: ".$To."\n";
$headers.="Reply-To: ".$FromName." <".$From.">\n";
$headers.="X-Priority: 1\n";
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";
//Messages start with text/html alternatives in OB
$Msg ="This is a multi-part message in MIME format.\n";
$Msg.="\n--".$OB."\n";
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";
// html section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/html;\n\tcharset=\"gb-2312\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$Msg.=chunk_split(base64_encode($Html))."\n\n";
// end of IB
$Msg.="\n--".$IB."--\n";
// attachments
if($AttmFiles){
foreach($AttmFiles as $AttmFile){
// $patharray = explode ("/", $AttmFile);
// $FileName=$patharray[count($patharray)-1];
$pos = strpos($AttmFile,".");
if ($pos === false)
break;
$FileName=$AttmFile;
// $FileName="d://php_work//softzixun//admin//upload//email//222707.jpg";
$mimeType=getContentType($FileName);
$Msg.= "\n--".$OB."\n";
$Msg.="Content-Type: $mimeType;\n\t name=\"".basename($FileName)."\"\n";
$Msg.="Content-Transfer-Encoding: base64\n";
$Msg.="Content-Disposition: attachment;\n\t filename=\"".basename($FileName)."\"\n\n";
if(ereg("txt",$contentType))
{
$textFile = fopen($FileName, "r");
while(!feof($textFile))
$Msg .= fgets($textFile,1000);
$Msg .= "n";
}
else
{
if ($fp = fopen($FileName,"rb"))
{
$content= fread($fp,filesize($FileName));
$Msg .=chunk_split(base64_encode($content))."\n";
}
}
//--关闭文件 fclose($textFile);
}
}
//message ends
$Msg.="\n--".$OB."--\n";
mail($To,$Subject,$Msg,$headers);
}
/**********************************************
函数: getContentType($inFileName)用于判断附件的类型
**********************************************/
function getContentType($inFileName){
//--去除路径
$inFileName = basename($inFileName);
//--去除没有扩展名的文件
if(strrchr($inFileName, ".") == false){
return "application/octet-stream";
}
//--提区扩展名并进行判断
$extension = strrchr($inFileName, ".");
switch($extension){
case ".gif": return "image/gif";
case ".gz": return "application/x-gzip";
case ".htm": return "text/html";
case ".html": return "text/html";
case ".jpg": return "image/jpeg";
case ".tar": return "application/x-tar";
case ".txt": return "text/plain";
case ".zip": return "application/zip";
default: return "application/octet-stream";
}
return "application/octet-stream";
}
?>
可是把程序到服务器,只有 txt 等小于 1024 的文件才可以,图片等不能显示,为什么?