错误的标头:未编码的 8 位字符问题


BAD HEADER: nonencoded 8-bit character issue

我正在使用PHP mail()发送带有附加CSV文件的电子邮件。我的问题是服务器将其中一些(实际上是其中大部分)邮件隔离。根据日志,原因是:

mail.info:Sep  9 21:34:08 mailout4 amavis[18812]: (18812-05-2) Passed BAD-HEADER-2 {RelayedOpenRelay,Quarantined}, [xxx.xxx.xxx.xxx] <xyz@ws15.surf-town.net> -> <xyz@xyz.com>, mail_id: skJU2BMP1ssu, Hits: 1.117, size: 5145, queued_as: BB1DE33018, 2571 ms
BAD-HEADER-2 refers to: CC_BADH.',2',   "id=%n - BAD HEADER: nonencoded 8-bit  character",

所以我认为这是由于 CSV 文件数据中的一些特殊字符而发生的?

发送邮件的代码如下所示(还有更多代码,但这会显示邮件标头等)。

//create attachment from array of data $csvdata
$attachment = chunk_split(base64_encode(create_csv_string($csvData,$filename))); 
// Make the body of the message
$body = "--$multipartSep'r'n"
    . "Content-Type: text/plain; charset=utf-8; format=flowed'r'n"
    . "Content-Transfer-Encoding: 7bit'r'n"
    . "'r'n"
    . "$body'r'n"
    . "--$multipartSep'r'n"
    . "Content-Type: text/csv'r'n"
    . "Content-Transfer-Encoding: base64'r'n"
    . "Content-Disposition: attachment; filename='"$filename'"'r'n"
    . "'r'n"
    . "$attachment'r'n"
    . "--$multipartSep--";
 $subject .= ' (' . date('Y-m-d H:i:s') . ')';
 $headers = array(
   "From: $from",
   "Reply-To: $from",
   "Content-Type: multipart/mixed; boundary='"$multipartSep'""
 );   
 $recievers = explode(','.$to);
 foreach ($recievers as $reciever) {
   mail($reciever, $subject, $body, implode("'r'n", $headers)); 
 }

你们中有人遇到过这个问题吗?

关于不需要更改服务器设置的修复程序的任何想法?

我也有类似的问题。原因是标题中的国际字符。您应该检查邮件标题的内容。如果您有权访问拒绝邮件的 amavis 邮件服务器,则可以通过更改 amavis 配置来修复它:

$allowed_header_tests{'8bit'} = 0;

希望这有帮助。