MIME编码折叠主题标头导致在调用mail()时发出警告 [英] MIME encoded folded Subject header results in warning when calling mail()

查看:234
本文介绍了MIME编码折叠主题标头导致在调用mail()时发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Subject头是MIME编码并且折叠 mail()导致PHP警告时:

When a Subject header is MIME encoded and folded mail() results in PHP warning:

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

=> 未发送。

主题行是RFC2047(第8节)中的示例之一。它折叠成两行, mail()不喜欢它。由于它在其他主机上正常工作,我怀疑一个错误的配置。

The subject line is one of the examples in RFC2047 (section 8). It is folded to two lines and mail() does not like it. Since it works fine on other hosts I suspect a wrong configuration. But which one would that be?

PHP是5.4.0版本

PHP is Version 5.4.0

有什么想法吗?

编辑:

有关php配置的一些详细信息:

Some more info regarding the php configuration:

'./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


推荐答案

你是正确的,例子应该只是工作,我可以读这个。但PHP文档中的另一个注意事项提到某些邮件传输代理会自动将 \\\
更改为 \r\\\
,因此如果您已经提供了 \r\\\
(变为 \r\r\\\
)。

You are correct that the example should just work as 'I can read this'. But another note in the PHP docs mentions that some mail transfer agents automatically change the \n to \r\n and thus leading to problems if you already provided \r\n (becomes \r\r\n).

所以你可以尝试使用下面的代码(虽然它不符合标准,你的邮件代理可能会使它变得顺应) >

So you could try using the code below (although it does not comply to the standards, your mail agent might make it complient)

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

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

PHP has little check for valid subject in the code it self, so its all handled by your mail agent.

PHP源代码(只有主题检查,看不到任何特殊的):

PHP sourcecode (only subject check, to see it doesnt do anything special):

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;
}

这篇关于MIME编码折叠主题标头导致在调用mail()时发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆