【发布时间】:2015-03-14 17:17:32
【问题描述】:
- 使用 tcpdf 生成的 pdf
- 直接在浏览器中打开时会给出正确的输出
- 当尝试发送邮件而不是下载到本地计算机时,它首先会正常打开
- 将邮件从 Thunderbird 转发给其他用户,该 pdf 文件已损坏并且 显示如下消息: “Adobe 阅读器无法打开‘nsmail-3.pdf’,因为它不是受支持的文件类型,或者 因为该文件已损坏(例如,它是作为电子邮件附件发送的并且未正确解码)。”
发送邮件的示例代码是
$fileName = 'output.pdf';
$fileatt = $pdfObj->Output('output.pdf', 'E');
$attachment = chunk_split($fileatt);
$eol = PHP_EOL;
$separator = md5(time());
$headers = 'From: Sender <test@testmail.com>'.$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= 'Content-Type: multipart/mixed; boundary="'.$separator.'"';
$mailMessage .= '--'.$separator.$eol;
$mailMessage .= 'Content-Type:text/html;Charset=ISO-8859-1'.$eol;
$mailMessage .= 'Content-Transfer-Encoding: 8bit'.$eol.$eol;
$mailMessage .= 'message content text'.$eol;
$eol = "\r\n";
$mailMessage .= '--'.$separator.$eol;
$mailMessage .= 'Content-Type: application/pdf; name="'.$fileName.'"'.$eol;
$mailMessage .= 'Content-Transfer-Encoding: base64'.$eol;
$mailMessage .= 'Content-Disposition: attachment; filename='.$fileName.$eol;
$mailMessage .= $attachment.$eol;
$mailMessage .= '--'.$separator.'--';
mail('test@testmail.com', $toEmailid, $subject, $mailMessage, $headers);
谁能建议我在上面的代码中哪里错了? 或与雷鸟或 Outlook 相关的问题?
【问题讨论】:
标签: php email pdf tcpdf thunderbird