对不起,上面这个垃圾代码太多,我把没用的注释掉了,<?php$from = " <kei@lx94>";
$to   = " <kei@lx94>";
$subject    = "添付ファイルテスト";
$body       = "添付ファイルテスト正文";
$filename   = "/work/cgi-bin/prs/test.txt";
$ret = send_mail($to, $from, $subject, $body, $cc = null, $bcc = null, $filename);
function send_mail($to, $from, $subject, $body, $cc = null, $bcc = null, $attachment = null)
{
$body = "BCC:$bcc\r\n$body\r\n";
$body = "CC:$cc\r\n$body\r\n";
$to_tmp = join("\r\n   ",explode(",",$to));
$body = "TO:$to_tmp\r\n$body\r\n"; mb_language("Japanese");
mb_internal_encoding("EUC-JP");
mb_detect_order("ASCII, JIS, UTF-8, EUC-JP, SJIS"); $to = "testmail@lx94";
$cc = "testmail@lx94";
$header .= 'From:'.$from."\r\n";
$header .= "Cc:".$cc."\r\n";
$header .= "Bcc:".$bcc."\r\n";
if ($attachment){ $fh = fopen($attachment,rb);
$attach = fread ($fh, filesize ($attachment));
fclose ($fh); $filename = basename($attachment);
$boundary = "_Boundary_" . uniqid(rand(1000,9999) . '_') . "_"; $subject = mb_encode_mimeheader( $subject ); $filename = mb_encode_mimeheader( $filename );
$attach   = chunk_split(base64_encode($attach),76,"\n"); if (!$mime) $mime = "application/octet-stream";
$header  = "To: ".$to."\n" .
"From: ".$from."\n" .
"X-Mailer: PHP/" . phpversion() . "\n".
"MIME-Version: 1.0\n" .
"Content-Type: Multipart/Mixed; boundary=\"".$boundary."\"\n" ; $mbody .= "--$boundary\n";
$mbody .= "Content-Type: text/plain; charset=ISO-2022-JP\n" .
"Content-Transfer-Encoding: 7bit\n";
$mbody .= "\n"; 
$mbody .= "$body\n";
$mbody .= "--".$boundary."\n";
$mbody .= "Content-Type: ".$mime."; name=\"".$filename."\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment; filename=\"".$filename."\"\n";
$mbody .= "\n";
$mbody .= "$attach\n";
$mbody .= "--$boundary--\n"; return mail(NULL, $subject, $mbody, $header);

}else{

return  mb_send_mail($to, $subject, $body, $header);
}
}?>

解决方案 »

  1.   

    show me the error log.
      

  2.   

    对不起,可能是我表述的不太清楚,
    上面的程序是正确的,
    我想全部送信处理使用mb_send_mail
    也就是return mail(NULL, $subject, $mbody, $header);
    替换成,
    return  mb_send_mail($to, $subject, $body, $header);结果是上面的分支,原来使用mail送信的那个地方,改称mb_send_mail之后,发信可以,但是无法解析成附件。
    不理解。php版本5.0,按理说直接把mail替换成mb_send_mail是没有问题的。
      

  3.   

    你提问等待时间太早了,而且今天是周一。mb_send_mail不是php标准的函数,所以,就是贴出了代码,一般人是没有时间帮你分析的mail是php的标准函数,所以,可以发送成功是无可厚非的
      

  4.   

    谢谢楼上,不过我还是想求个答案。
    看了MIME的协议,根本没有思路就是瞎试,
      

  5.   

    关注 手册上面看不出来什么 note里还有人说应该可以用。你看看这个人说的是不是有帮助~
    http://cn2.php.net/manual/zh/function.mb-send-mail.php#32273
      

  6.   

    very nice , 回家看看,谢谢楼上。
      

  7.   

    $mbody .= "--$boundary--\n";多段文本应该是-==dddd==开头 -==dddd==结尾才对
    而且内容编码后使用chuk函数分割一下最好。
    另外其实并没有必要为编码犯愁采用BASE64 ENCODE一下就可以了
    例如"Subject: =?gb2312?B?".base64_encode("subject")."?=";这样的代码可以使用任何编码(gb2312就是编码你可以换成UTF-8)
      

  8.   

    楼上
    对于boundary的写法我想我这里是没有问题的,
    http://jp2.php.net/manual/ja/ref.mail.php
    <?
      $mime_boundary_2 = "1_".$mime_boundary;  $msg .= "Content-Type: multipart/alternative; boundary=\"".$mime_boundary_2."\"".$eol;
      
      # Text Version
      $msg .= "--".$mime_boundary_2.$eol;
      $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
      $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
      $msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
      
      # HTML Version
      $msg .= "--".$mime_boundary_2.$eol;
      $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
      $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
      $msg .= $body.$eol.$eol;
      
      # New Subboundary Finished
      $msg .= "--".$mime_boundary_2."--".$eol.$eol;   # Top-Boundary Finished
      $msg .= "--".$mime_boundary."--".$eol.$eol; 
    ?>看来不是非要-==dddd==开头结尾的。你说的那个chun函数应该是
    <?php
    $new_string = chunk_split(base64_encode($data));
    ?>
    吧。我的程序里面有啊。
    对于编码的问题,邮件文本采用EUC-JP编码,和文本采用SHIFT-JIS编码,这个是不变的。谢谢楼上了。
      

  9.   

    急求PHP mail()函数配置问题