我搜索了堆栈溢出,但我找不到问题的答案。
我正在尝试附加一个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变量以确保选择了正确的文件,它是。
有关问题的建议吗?
谢谢!
答案 0 :(得分:0)
您未向addAttachment
提供所有参数 - 请参阅http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php
特别是第三个$name
参数对您来说应该很有趣。