0

当 Subject 标头经过 MIME 编码和折叠mail()时会导致 PHP 警告:

<?php
$mime_subject = "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\r\n =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=";
mail( "name@domain.com", $mime_subject , "Hallo");

=>mail(): Bad parameters to mail() function, mail not sent.

主题行是 RFC2047(第 8 节)中的示例之一。它被折叠成两行,mail()不喜欢它。由于它在其他主机上运行良好,我怀疑配置错误。但那会是哪一个呢?

PHP 是版本 5.4.0

有任何想法吗?

编辑:

有关 php 配置的更多信息:

'./configure' '--prefix=/home/www/PHP/php-5.4.0' '--with-openssl'
    '--with-zlib-dir=/usr/lib/' '--with-jpeg-dir=/usr/lib/' '--with-mysql'
    '--enable-fastcgi' '--with-informix=/opt/informix'
    '--with-oci8=shared,instantclient,/opt/oracleclient/instantclient,10.2'
    '--enable-pcntl' '--with-gettext' '--with-ldap' '--with-curl'
    '--with-gd' '--with-freetype-dir=/usr/include/freetype2/' '--with-dom'
    '--enable-bcmath' '--enable-soap' '--enable-mbstring'
    '--with-mcrypt=shared,/usr/local/libmcrypt' '--enable-pdo'
    '--with-pdo-mysql' '--enable-zip' '--with-imap' '--with-kerberos'
    '--with-imap-ssl' '--with-ldap-sasl' '--with-icu-dir=/usr' '--enable-intl'

mail.add_x_header   Off Off
mail.force_extra_parameters no value    no value
mail.log    no value    no value
sendmail_from   no value    no value
sendmail_path   /usr/sbin/sendmail -t -i    /usr/sbin/sendmail -t -i 
SMTP    localhost   localhost
smtp_port   25  25

mailparse version 2.1.6
4

1 回答 1

1

你是对的,这个例子应该像“我可以读到这个”一样工作。但是 PHP 文档中的另一个注释提到,一些邮件传输代理会自动更改\nto ,因此如果您已经提供(becomes ) 会\r\n导致问题。\r\n\r\r\n

所以您可以尝试使用下面的代码(虽然它不符合标准,但您的邮件代理可能会使其符合标准)

<?php
$mime_subject = "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\n=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=";
mail( "name@domain.com", $mime_subject , "Hallo");
?>

PHP 在它自己的代码中几乎没有检查有效主题,所以它全部由您的邮件代理处理。

PHP 源代码(仅主题检查,看它没有做任何特别的事情):

if (subject_len > 0) {
  subject_r = estrndup(subject, subject_len);
  for (; subject_len; subject_len--) {
    if (!isspace((unsigned char) subject_r[subject_len - 1])) {
      break;
    }
    subject_r[subject_len - 1] = '\0';
  }
  for (i = 0; subject_r[i]; i++) {
    if (iscntrl((unsigned char) subject_r[i])) {

      /* According to RFC 822, section 3.1.1 long headers may be separated into
       * parts using CRLF followed at least one linear-white-space character ('\t' or ' ').
       * To prevent these separators from being replaced with a space, we use the
       * SKIP_LONG_HEADER_SEP to skip over them. */

      SKIP_LONG_HEADER_SEP(subject_r, i);
      subject_r[i] = ' ';
    }
  }
} else {
  subject_r = subject;
}
于 2013-04-29T12:53:17.723 回答