某些邮件客户端在从sendmail切换到qmail后,会从PHP邮件()中看到空的CSV附件
问题描述:
以下代码多年来一直向我们的印刷履行人员发送CSV。本周开始,系统管理员从sendmail切换到qmail,原因是与我们想运行的procmail配方有关。某些邮件客户端在从sendmail切换到qmail后,会从PHP邮件()中看到空的CSV附件
大概不是巧合,我们开始听到履行人员看到空的CSV,即使其他人在邮件上看到记录时也是如此。有问题的人看到附件并可以打开它,但他们的MUI将其列为131字节或零字节。
我们开始发送到雅虎地址,结果相同。不过,Gmail会使用正确的行查看附件。请注意,这是根据邮件客户端的不同结果的所有CCed电子邮件。
我已经在vi中的代码,并确保没有^ M字符或其他控制字符垃圾。
以前有人看过这个吗?任何建议最受欢迎!
谢谢!
$message = "Here is the file (comma-separated values) of addresses for\n";
$message .= $pm_row['title'] . " Requests ($now_YmdHMS).\n\n";
$data_email = $pm_row['fulfillment_data_email'];
$data_email_cc = "$pm_row[fulfillment_data_email_cc],$developer_email";
$subject = $pm_row['title'] . " Requests ($now_YmdHMS)";
$random_hash = md5(date('r', time()));
$headers = "From: XXX <[email protected]>\r\nReply-To: [email protected]\r\nCc:$data_email_cc";
$headers .= "\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
$output = "
--PHP-mixed-$random_hash;
Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash'
--PHP-alt-$random_hash
Content-Type: text/plain; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
$message
--PHP-alt-$random_hash
Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
$message
--PHP-alt-$random_hash--
--PHP-mixed-$random_hash
Content-Type: application/zip; name=$now_YmdHMS.$pm_row[handle].csv
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$random_hash--";
mail($data_email, $subject, $output, $headers);
答
我认为这是一个CR/LF问题,这是在PHP中的已知的bug,大约三年 - 作为据我知道 - 没有被固定到现在:
http://bugs.php.net/bug.php?id=15841
由于使用了不符合RFC的换行格式,生成的电子邮件无效(可在此处找到解释:http://cr.yp.to/docs/smtplf.html)。其他MTA如sendmail和postfix自动纠正此问题; qmail没有。
您可以:编写正确的邮件用PHP(笑),或问你的qmail管理员使用QmailScanner(http://qmail-scanner.sourceforge.net/),这也太做这个工作。
最好的解决办法是卸载PHP和未来鸭用perl;)
我原本一个Perl的人辩论。当Perl是你的锤子时,这个世界看起来就像是世界。感谢您的链接和信息! – jerrygarciuh 2010-07-13 14:30:19