php
  • email
  • pear
  • 2016-05-13 45 views 0 likes 
    0

    我已經搜索了堆棧溢出,並且找不到問題的答案。PHP Pear Mail - 添加zip附件

    我想附加一個zip文件作爲電子郵件附件自動發送PEAR郵件。以下是我正在使用的代碼:

    require_once "Mail.php"; 
    require_once "mime.php"; 
    
    $from = '<[email protected]>'; 
        $to = '<[email protected]>'; 
        $subject ='Test stocktake summary reports' ; 
        //$body = "Hello,\n\nReports for test site have been uploaded and can be accessed by logging in to http://192.168.3.44/ using the following credentials:\n\nusername:testUser \n\npassword:testPassword\n\nKind Regards,\n\n Supervisor Name"; 
    
        $text = 'Text version of email'; 
        $html = '<html><body>HTML version of email</body></html>'; 
        $file = 'C:/Temp/Reports'.$this->stocktake_id.'.zip'; 
    
        echo $file; 
        //die(); 
        $crlf = "rn"; 
        $hdrs = array(
            'From' => $from, 
            'To'  => $to, 
            'Subject' => $subject 
           ); 
    
        $mime = new Mail_mime($crlf); 
    
        $mime->setTXTBody($text); 
        $mime->setHTMLBody($html); 
    
        $mime->addAttachment($file,'application/zip'); 
    
        $body = $mime->get(); 
        $hdrs = $mime->headers($hdrs); 
    
        $smtp = Mail::factory('smtp', array(
            'host' => 'DNS SERVER', 
            'port' => '465', 
            'auth' => true, 
            'username' => 'USERNAME', 
            'password' => 'PASSWORD' 
           )); 
    
        $mail =& Mail::factory('mail', $params); 
        $mail = $smtp->send($to, $hdrs, $body); 
    
    
        if (PEAR::isError($mail)) { 
         echo('<p>' . $mail->getMessage() . '</p>'); 
        } else { 
         echo('<h2>Message successfully sent!</h2>'); 
        } 
    

    該代碼部分工作。它發送電子郵件,它附加文件,但附加文件被稱爲「noname」,沒有擴展名。我嘗試回顯$ file變量以確保正確選擇了正確的文件,並且是。

    有什麼問題是什麼建議?

    謝謝!

    回答

    0

    你不提供所有參數addAttachment - 看到http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php

    的文件特別是第三$name參數應該是有趣的你。

    相關問題