Php 使用Zend_Mail时添加PDF附件

Php 使用Zend_Mail时添加PDF附件,php,email,zend-framework,attachment,zend-mail,Php,Email,Zend Framework,Attachment,Zend Mail,使用Zend_Mail时,添加附件的正确方法是什么?当我试图在发送的邮件中打开附加的pdf时,我不断收到以下错误:“无法提取嵌入的字体‘Baaaaa+ArialMT’。某些字符可能无法正确显示或打印。”pdf仅显示表格,但不显示字符 这是非常奇怪的,因为如果我直接从服务器或本地主机下载PDF,它会正确打开 这是我用来发送附件的代码: $html = $view->render('email/invoice.phtml'); $mail = new Zend_Mail("utf-8");

使用Zend_Mail时,添加附件的正确方法是什么?当我试图在发送的邮件中打开附加的pdf时,我不断收到以下错误:“无法提取嵌入的字体‘Baaaaa+ArialMT’。某些字符可能无法正确显示或打印。”pdf仅显示表格,但不显示字符

这是非常奇怪的,因为如果我直接从服务器或本地主机下载PDF,它会正确打开

这是我用来发送附件的代码:

$html = $view->render('email/invoice.phtml');
$mail = new Zend_Mail("utf-8");

$file = PUBLIC_PATH . DS . 'data' . DS . $invoice . '.pdf';
$at = new Zend_Mime_Part(file_get_contents($file));
$at->filename = basename($file);
$at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$mail->addAttachment($at);

/* Here i add the attachment */
$mail->setBodyHtml($html);
$mail->addTo($order->email, 'Factura '. $invoice . ' '.Zend_Registry::get('siteName'));
$mail->setFrom('vanzari@anunt.com', Zend_Registry::get('siteName'));
$mail->setSubject('Factura '. $invoice . ' '.Zend_Registry::get('siteName'));
$mail->send();

这是正确的方法

$mail = new Zend_Mail();
$mail->setBodyHtml("description");
$mail->setFrom('id', 'name');
$mail->addTo(email, name);
$mail->setSubject(subject);

$content = file_get_contents("path to pdf file"); // e.g. ("attachment/abc.pdf")
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename = 'filename.pdf'; // name of file

$mail->addAttachment($attachment);                  

$mail->send(); 

谢谢,这很有效。你是否也改变了我存放pdf附件的部分的顺序(在设置主题、地址和电子邮件正文之后),或者只是编码很重要?