附件实际上是一个mime段
不知道你是怎么发送已存在的文件的,
不过道理是一样的

解决方案 »

  1.   

    就是先从数据库里把符合条件的纪录选择出来,是不是需要生成一个文件?然后再作为附件发送?
    我以前用的下载程序,只需要文件头加上
    Header("Content-disposition: attachment; filename=support.csv");
    Header("Content-type: application/octet-stream; name=support.csv");
    这两句话,就可以下载下来了,这时候可以添加条件进行查询,按照常规的打印语句,就把文件以csv格式下载下来了。
    我现在有的一个发附件的函数程序,它是需要已经存在的文件作为附件才可以,所以我的这种情况就不知道怎么处理了。
    http://community.csdn.net/Expert/topic/3186/3186904.xml?temp=.9640924
      

  2.   

    那个发附件的程序因该有直接写str的方法的,没有的话也可以改一下啊从数据库读取出来以后如果可以直接写str的话就不用另外生成文件了
      

  3.   

    第一次涉及到传附件,好多我不太明白,讀出來的數據是几十条數據,不生成文件的话,我怎么能最为附件上传呢?现在这个传附件的也是以文件形式的,我贴出来麻烦你再指点一下,谢谢!
    function mail2( $to, $subject, $message, $from, $content_type, $attache="") {
      if(!empty($from)) $head = "From: $from\n";
      if(empty($content_type)) $content_type = "text/plain";  if(is_array($attache)) {
        $boundary = "===" . md5(uniqid("")) . "===";
        $head .= "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"";
        $head .= "$boundary\"\n\nThis is a multi-part message in MIME format.\n\n";
        $head .= "--$boundary\n";
        $head .= "Content-Type: $content_type\n";
        $head .= "\n$message\n\n";    while(list($key, $val) = each($attache)) {
          $fd = fopen("$val", "r") or die("unable to open file $val");
          $contents = chunk_split(base64_encode(fread($fd,filesize("$val"))));
          fclose($fd);
          $head .= "--$boundary\n";
          $head .= "Content-Type: application/octet-stream; name=\"".basename($val);
          //$head .= "Content-Type: application/octet-stream; name=support.csv;
          $head .= "\"\nContent-Transfer-Encoding: BASE64\n";
          $head .= "Content-Disposition: attachment; filename=\"".basename($val);
          $head .= "\"\n\n" . $contents . "\n\n";
        }
        $head .= "--" . $boundary . "--\n\n";
      }else{
        if(!empty($content_type)) {
          $head .= "Content-Type: $content_type\n";
          $head .= "\n$message\n";
        }
      }
      return mail($to,$subject,"",$head );
    }mail2("$send_to","",$message,"","",array("support.csv"));
      

  4.   

    $fd = fopen("$val", "r") or die("unable to open file $val");
    $contents = chunk_split(base64_encode(fread($fd,filesize("$val"))));
    这里把fread换成你的字符串就可以了