2010-09-30 77 views
0

我需要一些幫助,在這裏有一個非常奇怪的情況..我做了一個webmail表單發送多個附件的電子郵件,它昨天開箱即用,但今天它只發送1個文件作爲附件和不是多個。 O_Ophp郵件附件奇怪的行爲

我恢復我的SVN到一個較舊的版本也問題仍然存在,任何想法?這真的很奇怪..如何工作的東西剎車從一天到另一天,我認爲這個問題一定是SMTP服務器或什麼的。請幫助!

代碼:

 $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 


      $attachments = TRUE; 
     $body = "This is a multi-part message in MIME format.\n\n" . 
     "--{$mime_boundary}\n" . 
     "Content-Type: text/plain; charset=iso-8859-1\n" . 
     "Content-Transfer-Encoding: 7bit\n\n" . 
     $body . "\n\n"; 
     $body .= "--{$mime_boundary}\n"; 
     $attach = array(); 
     for($i=0; $i<count($_FILES['file']['name']);$i++) 
     { 
      $tmp_name = $_FILES['file']['tmp_name'][$i]; 
      $type = $_FILES['file']['type'][$i]; 
      $name = $_FILES['file']['name'][$i]; 
      $size = $_FILES['file']['size'][$i]; 

      if (file_exists($tmp_name)){ 
       $kb = $size/1024; 
       $kbSize = round($kb*100)/100; 

       if(is_uploaded_file($tmp_name)){ 
        $file = fopen($tmp_name,'rb'); 
        $fdata = fread($file,filesize($tmp_name)); //stream file to var and send it in headers 
        fclose($file); 
        $fdata = chunk_split(base64_encode($fdata)); 
        $body .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" . 
         "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" . 
         "Content-Transfer-Encoding: base64\n\n" . $fdata . "\n\n"; 
        $body .= "--{$mime_boundary}-\n"; 
       } 
      }  
     } 
     $sent = myMailer::sendAttached($from,$to,$subject,$body,$mime_boundary,$multi); 

MyMailer類,sendAttached方法:

public static function sendAttached($from,$to,$subject,$body,$mime,$multi=FALSE) 
{ 

    $headers = 'From: Website <'.$from.'>'. "\r\n". 
    'Reply-To: '.$from. "\r\n". 
    "MIME-Version: 1.0\r\n" . 
    "Content-Type: multipart/mixed;\r\n" . 
    " boundary=\"{$mime}\""; 

    if($multi == TRUE && is_array($to)){ 
     foreach($to as $item) 
     { 
      mail(trim($item),$subject,$body,$headers); 
     } 
     return TRUE; 
    }else{ 
     return mail($to,$subject,$body,$headers); 
    } 
} 
+2

'cat your_code | stackoverflow - 問題>答案......換句話說...發佈你的代碼:-) – prodigitalson 2010-09-30 14:15:22

+0

那裏你是:) ..代碼是不是問題,因爲我說..這是工作,我恢復到修改在svn中,仍然發送1個而不是3個附件,因爲它用於發送 – cosmicodelnorte 2010-09-30 15:15:34

回答

0

難道你也許在某個時刻的舉動西奧的for外循環以下:

$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

我從來沒有嘗試過像這樣從頭創建一個複雜的多部分信息(我總是我們e像Swift Mailer或Zend_Mail這樣的現有庫),但不是每個文件都必須是它自己的部分,因此有它自己的邊界?