【发布时间】: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 变量以确保选择了正确的文件。
对问题所在有什么建议吗?
谢谢!
【问题讨论】: