【问题标题】:PHP Pear Mail - Adding zip attachmentPHP Pear Mail - 添加 zip 附件
【发布时间】:2016-05-13 06:32:55
【问题描述】:

我搜索了堆栈溢出,但找不到问题的答案。

我正在尝试将 zip 文件作为附件附加到由 PEAR 邮件自动发送的电子邮件中。以下是我正在使用的代码:

require_once "Mail.php";
require_once "mime.php";

$from = '<arturl@stocktaking.ie>';
    $to = '<artlemaks@gmail.com>';
    $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 变量以确保选择了正确的文件。

对问题所在有什么建议吗?

谢谢!

【问题讨论】:

    标签: php email pear


    【解决方案1】:

    您没有向addAttachment 提供所有参数 - 请参阅http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php 的文档

    尤其是第三个$name 参数你应该会感兴趣。

    【讨论】:

      猜你喜欢
      • 2014-09-04
      • 2012-05-14
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 2010-12-02
      • 2018-06-04
      • 2012-06-12
      • 2011-04-20
      相关资源
      最近更新 更多