php
  • email
  • pear
  • 2016-05-13 78 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参数应该是有趣的你。

    相关问题