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");
=> mail(): Bad parameters to mail() function, mail not sent.
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 is Version 5.4.0
Any ideas?
EDIT:
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
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 has little check for valid subject in the code it self, so its all handled by your mail agent.
PHP sourcecode (only subject check, to see it doesnt do anything special):