使用Zend_Mail时添加PDF附件 [英] Adding an PDF attachment when using Zend_Mail

查看:128
本文介绍了使用Zend_Mail时添加PDF附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Zend_Mail时添加附件的正确方法是什么?当我尝试在发送的邮件中打开附带的pdf时,我会收到以下错误:无法提取嵌入式字体BAAAAAA + ArialMT,有些字符可能无法正确显示或打印。 PDF仅显示表格,但不显示任何字符。

What is the right way to add an attachment when using Zend_Mail? I keep getting the following error when I try to open the attached pdf in the sent mail: "Cannot extract the embedded font 'BAAAAAA+ArialMT'. Some characters may not display or print correctly." The PDF shows only the table but no characters.

这是非常奇怪的,因为如果我直接从服务器或我的本地主机下载,则打开corectly。

This is very weird because the PDF opens corectly if i download it directly from the server or on my localhost.

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

This is the code I used for sending the attachement:

$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();


推荐答案

这是正确的方法, p>

Here is the right way to do it,

$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(); 

这篇关于使用Zend_Mail时添加PDF附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆