我有一个奇怪的问题,不知道如何解决它。我在Zend框架控制器,允许管理员登录,上传PDF,并作为附件发送至所有订阅邮件列表之一创建的脚本。问题是,一些用户报告说,他们无法打开PDF附件,该文件已损坏。我认为,这只是发生在AOL用户,但我还不能肯定。你有没有遇到过这个问题吗?或者,也许它不是与AOL的一个问题,但有毛病我的代码?

下面是不工作的代码:

此外,我使用ZF版本1.6.0。不知道这是相关的。

//assuming the form is valid:
$table = new Subscribers();
$rowset = $table->fetchAll();
foreach ($rowset as $row) {
    $mail = new Zend_Mail();
    $mail->setBodyText($form->getElement('body')->getValue())
         ->setFrom('weekly-update@email.com', 'Weekly Update')
         ->addTo($row->email)
         ->setSubject($form->getElement('subject')->getValue());
    $fileLocation = $form->getElement('attachment')->getValue();
    $fileContents = file_get_contents($fileLocation);
    $attachment = $mail->createAttachment($fileContents);
    $attachment->filename = str_replace(Zend_Registry::get('config')->downloadsLocation . '/', '', $fileLocation);          
    $mail->send();
}
有帮助吗?

解决方案

似乎(我),在这行代码:

$attachment = $mail->createAttachment($fileContents);

您可能需要添加的可用附加报头信息中的Zend_Mail框架::

的createAttachment方法
$attachment = $mail->createAttachment($fileContents,
                        Zend_Mime::DISPOSITION_INLINE);

许多大型电子邮件服务提供商都拘泥于严格遵守好电子邮件策略(我发现)。

玩弄这一点,我相信你会得到它的工作。

其他提示

我也有这个问题。

我建议你以某种方式描绘出文件流信息。与我的应用程序的问题是,$fileContents = file_get_contents($fileLocation);呼吁没有得到正确的文件流,所以这是你可能会掉下来。

尝试这种情况:

$mail = new Zend_Mail();
...
var_dump($mail->send());

您应该看到一堆乱码所在的文件流中的下键的var_dump出来:

["_content:protected"]=>
        string(37129) "%PDF-1.5
        etc...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top