尝试从 thunderbird/outlook 转发邮件时 pdf 文件损坏
pdf file corrupted when try to forward mail from thunderbird/outlook
- 使用 tcpdf 生成 pdf
- 当直接在浏览器中打开它时,它提供正确的输出
- 当尝试发送邮件而不是下载到本地计算机时,第一次出现它可以正常打开
- 将邮件从 thunderbird 转发给其他用户,该 pdf 文件已损坏并且
显示如下消息:
“Adobe reader 无法打开 '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);
谁能告诉我上面代码哪里错了?
或其 thunderbird 或 outlook 相关问题?
- 使用替代解决方案在邮件中发送 pdf 文件,即将文件存储在服务器上,发送带有附件的电子邮件,在邮件发送后从服务器中删除文件。
示例代码
$fileName = 'output.pdf';
$fileatt = $pdfObj->Output(SERVERPATH.'/output.pdf', 'F');
$filename = 'output.pdf';
$file = $naTmpPath.'/'.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$attachment = chunk_split(base64_encode($content));
$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);
- 使用 tcpdf 生成 pdf
- 当直接在浏览器中打开它时,它提供正确的输出
- 当尝试发送邮件而不是下载到本地计算机时,第一次出现它可以正常打开
- 将邮件从 thunderbird 转发给其他用户,该 pdf 文件已损坏并且 显示如下消息: “Adobe reader 无法打开 '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);
谁能告诉我上面代码哪里错了? 或其 thunderbird 或 outlook 相关问题?
- 使用替代解决方案在邮件中发送 pdf 文件,即将文件存储在服务器上,发送带有附件的电子邮件,在邮件发送后从服务器中删除文件。
示例代码
$fileName = 'output.pdf';
$fileatt = $pdfObj->Output(SERVERPATH.'/output.pdf', 'F');
$filename = 'output.pdf';
$file = $naTmpPath.'/'.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$attachment = chunk_split(base64_encode($content));
$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);