代码之家  ›  专栏  ›  技术社区  ›  jerrygarciuh

在从sendmail切换到qmail之后,一些邮件客户端会看到php mail()中的空csv附件。

  •  0
  • jerrygarciuh  · 技术社区  · 15 年前

    下面的代码多年来一直在向我们的打印履行人员发送CSV。本周初,系统管理员从sendmail切换到qmail,原因与我们要运行的procmail配方有关。

    很可能不是巧合,我们开始听说履行人们看到空的CSV,即使其他CCED在邮件看到记录。有问题的人看到了附件,可以打开它,但他们的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 <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);
    
    1 回复  |  直到 13 年前
        1
  •  1
  •   Erik    15 年前

    我认为这是一个CR/LF问题,它在PHP中是一个已知的bug,大约三年了,据我所知,到目前为止还没有解决:

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

    生成的电子邮件无效(此处可找到解释: http://cr.yp.to/docs/smtplf.html ,因为使用了不符合RFC的换行符格式。其他MTA(如sendmail和postfix)会自动更正此问题;qmail不会。

    你也可以:用PHP写正确的邮件( 大声笑 )或要求qmail管理员使用qmailscanner( http://qmail-scanner.sourceforge.net/ ,这也是在做这项工作。

    最好的解决方案是卸载PHP并在将来使用Perl 鸭子 ;)

    推荐文章