【问题标题】:Multiple attachments in sent folder using Imap_Append in PHP使用 PHP 中的 Imap_Append 在已发送文件夹中添加多个附件
【发布时间】:2014-07-31 16:06:58
【问题描述】:

我正在使用以下代码使用 IMAP_APPEND 在已发送文件夹中的邮件消息中添加多个附件。在已发送的文件夹中,我只收到一个附件,没有其他附件。任何人都可以建议这是什么问题吗??

    if ($mbox=imap_open( $authhost, $user, $pass)) 
        { 

            $dmy=date("d-M-Y H:i:s"); 
            $boundary = "------=" . md5(uniqid(rand()));
            $msg .= "From: ".$from[0]."\r\n" 
                . "To: ".$recipients[$key][0]."\r\n" 
                . "CC: ".$ccList."\r\n" 
                . "Date: $dmy\r\n" 
                . "Subject: $subject\r\n"                   
                . "MIME-Version: 1.0\r\n" 
                . "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n" 
                . "\r\n\r\n" 
                . "--$boundary\r\n" 
                . "Content-Type: text/html;\r\n\tcharset=\"ISO-8859-1\"\r\n" 
                . "Content-Transfer-Encoding: 8bit \r\n" 
                . "\r\n\r\n" 
                . $body . "\r\n" 
                . "\r\n\r\n" 
                . "--$boundary\r\n" 
                . "Content-Transfer-Encoding: base64\r\n"; 


                foreach($attachment as $attchURL){
                    $files = $_SERVER['DOCUMENT_ROOT'] . "/attachments/" . $attchURL;
                    $filename = substr($attchURL, strrpos($attchURL,"/")+1);
                    $ouv=fopen ("$files", "rb");$lir=fread ($ouv, filesize ("$files"));
                    fclose($ouv);
                    $attachments = chunk_split(base64_encode($lir));                        
                    $msg .= "Content-Disposition: attachment; filename=\"$filename\"\r\n" ;                     
                    $msg .=  "\r\n" . $attachments . "\r\n"; 
                }
                $msg .= "\r\n\r\n\r\n" 
                . "--$boundary--\r\n\r\n"; 

            imap_append($mbox,$authhost,($msg)); 
            imap_close($mbox); 
        }   

【问题讨论】:

    标签: php email imap


    【解决方案1】:
     if ($mbox=imap_open( $authhost, $user, $pass)) 
        { 
    
            $dmy=date("d-M-Y H:i:s"); 
            $boundary = "------=" . md5(uniqid(rand()));
            $msg .= "From: ".$from[0]."\r\n" 
                . "To: ".$recipients[$key][0]."\r\n" 
                . "CC: ".$ccList."\r\n" 
                . "Date: $dmy\r\n" 
                . "Subject: $subject\r\n"                   
                . "MIME-Version: 1.0\r\n" 
                . "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n" 
                . "\r\n\r\n" 
                . "--$boundary\r\n" 
                . "Content-Type: text/html;\r\n\tcharset=\"ISO-8859-1\"\r\n" 
                . "Content-Transfer-Encoding: 8bit \r\n" 
                . "\r\n\r\n" 
                . $body . "\r\n" 
                . "\r\n\r\n"; 
    
    
                foreach($attachment as $attchURL){
                    $files = $_SERVER['DOCUMENT_ROOT'] . "/attachments/" . $attchURL;
                    $filename = substr($attchURL, strrpos($attchURL,"/")+1);
                    $ouv=fopen ("$files", "rb");$lir=fread ($ouv, filesize ("$files"));
                    fclose($ouv);
                    $attachments = chunk_split(base64_encode($lir));                        
    
    
                    $msg .=  "--$boundary\r\n" 
                    $msg .=  "Content-Transfer-Encoding: base64\r\n"; 
                    $msg .= "Content-Disposition: attachment; filename=\"$filename\"\r\n" ;                     
                    $msg .=  "\r\n" . $attachments . "\r\n"; 
                }
                $msg .= "\r\n\r\n\r\n" 
                . "--$boundary--\r\n\r\n"; 
    
            imap_append($mbox,$authhost,($msg)); 
            imap_close($mbox); 
        }  
    

    【讨论】:

    • 最好在代码中包含解释
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-01
    • 2013-07-04
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    相关资源
    最近更新 更多