简体   繁体   English

从sendmail切换到qmail后,某些邮件客户端从PHP mail()看到空的CSV附件

[英]Some mail clients see empty CSV attachment from PHP mail() after switch from sendmail to qmail

The code below has been sending CSVs to our print fulfillment folks for years. 多年来,以下代码已将CSV发送给我们的打印实现人员。 Beginning of the week the sysadmin switched from sendmail to qmail for reasons having to do with procmail recipes we want to run. 从本周开始,由于与我们要运行的procmail配方有关的原因,系统管理员从sendmail切换到qmail。

Probably not coincidentally we starting started hearing that the fulfillment folks were seeing empty CSVs even when others CCed on the mail saw the records. 可能并非偶然,我们开始听到,即使邮件中抄送的其他人看到了记录,履行人员也看到了空的CSV。 Folks with the issue were seeing the attachment and could open it but their MUI was listing it as 131 bytes or zero bytes. 有问题的人可以看到附件并可以打开它,但是他们的MUI将其列为131字节或零字节。

We started sending to a Yahoo address with same results. 我们开始发送到Yahoo地址,结果相同。 However Gmail sees attachment with correct rows. 但是,Gmail看到带有正确行的附件。 Mind you this is all one CCed email with different results depending on mail clients. 请注意,这是一封CCed电子邮件,根据邮件客户端的不同结果。

I have gone over the code in vi and made sure there were no ^M chars or other control character junk. 我已经遍历了vi中的代码,并确保没有^ M字符或其他控制字符垃圾。

Anyone seen this before? 有人看过吗? Any suggestions most welcome! 任何建议最欢迎!

Thanks! 谢谢!

$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 <tourism@xxx.org>\r\nReply-To: tourism@xxx.org\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);

I think it is a CR/LF problem, which is a known Bug in php for about three years and -as far as I know- hasn't been fixed up to now: 我认为这是一个CR / LF问题,大约三年来,这是php中的一个已知错误,并且-据我所知-到目前为止尚未修复:

http://bugs.php.net/bug.php?id=15841 http://bugs.php.net/bug.php?id=15841

The generated Email isn't valid (explanation can be found here: http://cr.yp.to/docs/smtplf.html ), due to using a non-RFC-conform linebreak-format. 由于使用了不符合RFC的换行格式,因此生成的电子邮件无效(可在此处找到说明: http : //cr.yp.to/docs/smtplf.html )。 Other MTA like sendmail and postfix correct this problem automatically; 其他MTA(例如sendmail和postfix)会自动解决此问题; qmail doesn't. qmail没有。

You can either: write correct mails with php ( lol ), or ask your qmail-administrator to use the QmailScanner ( http://qmail-scanner.sourceforge.net/ ), which is doing this job too. 您可以:用php( lol )编写正确的邮件,或要求您的qmail管理员使用QmailScanner( http://qmail-scanner.sourceforge.net/ ),这也可以完成此工作。

The best solution would be to deinstall php and use perl in the future duck ;) 最好的解决方案是卸载php并在以后的鸭子中使用perl;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM