php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30766 mail() adds headers and encodes the body
Submitted: 2004-11-12 01:44 UTC Modified: 2004-11-14 04:38 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: aflem26 at hotmail dot com Assigned:
Status: Closed Package: Mail related
PHP Version: 4.3.9 OS: RHEL 3.0
Private report: No CVE-ID: None
 [2004-11-12 01:44 UTC] aflem26 at hotmail dot com
Description:
------------
system: vanilla rhel 3.0
original php version: 4.3.2
manually compiled and installed 4.3.9, but the bug persists

I have noticed that simple mail() calls result in php adding erroneous headers in addition to and in conflict with those that I supply.  In particular, the erroneous headers are:
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: BASE64


and php encoding the body into base 64, which shouldn't happen:
"body" gets encoded as Ym9keQ==




*please*, if this is to be expected, point me to some documentation, or some explanation.  All my web based mail tools are broken due to the additional header, and mail I send through them comes out all garbled, because the mail script encodes the message, and then It gets encoded *again*. please. 


Thanks so much.



my config line is as follows (long!): ./configure --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --target=i386-redhat-linux --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-force-cgi-redirect --disable-debug --enable-pic --disable-rpath --enable-inline-optimization --with-bz2 --with-db4=/usr --with-curl --with-dom=/usr --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-png-dir=/usr --with-gd --enable-gd-native-ttf --with-ttf --with-gettext --with-ncurses --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-png --with-pspell --with-regex=system --with-xml --with-expat-dir=/usr --with-zlib --with-layout=GNU --enable-bcmath --enable-exif --enable-ftp --enable-magic-quotes --enable-safe-mode --enable-sockets --enable-sysvsem --enable-sysvshm --enable-discard-path --enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex --without-oci8 --with-pear=/usr/share/pear  --with-kerberos=/usr/kerberos --with-ldap=shared --with-mysql=shared,/usr --with-pgsql=shared --with-unixODBC=shared --enable-memory-limit --enable-bcmath --enable-shmop --enable-versioning --enable-calendar --enable-dbx --enable-dio --enable-mcal --with-apxs2filter=/usr/sbin/apxs

Reproduce code:
---------------
$more test.php
<?
  $header = "Content-Type: text/plain; charset=us-ascii";
  mail('joe@test.com', 'subject', 'body', $header);
?>


Expected result:
----------------
Here's What I would Expect:
$php -d sendmail_path=/bin/cat test.php
To: joe@test.com
Subject: subject
Content-Type: text/plain; charset=us-ascii

body



Actual result:
--------------
Here's what I get.  Please note the erroneous and conflicting Content-Type header, and the un-invited content-transfer encoding that has been applied: 

$php -d sendmail_path=/bin/cat test.php
To: joe@test.com
Subject: subject
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: BASE64

Ym9keQ==



Here's the same thing, piped through xdd:

$php -d sendmail_path=/bin/cat test.php | xxd
0000000: 546f 3a20 6a6f 6540 7465 7374 2e63 6f6d  To: joe@test.com
0000010: 0a53 7562 6a65 6374 3a20 7375 626a 6563  .Subject: subjec
0000020: 740a 436f 6e74 656e 742d 5479 7065 3a20  t.Content-Type:
0000030: 7465 7874 2f70 6c61 696e 3b20 6368 6172  text/plain; char
0000040: 7365 743d 7573 2d61 7363 6969 0a4d 696d  set=us-ascii.Mim
0000050: 652d 5665 7273 696f 6e3a 2031 2e30 0a43  e-Version: 1.0.C
0000060: 6f6e 7465 6e74 2d54 7970 653a 2074 6578  ontent-Type: tex
0000070: 742f 706c 6169 6e3b 2063 6861 7273 6574  t/plain; charset
0000080: 3d55 5446 2d38 0a43 6f6e 7465 6e74 2d54  =UTF-8.Content-T
0000090: 7261 6e73 6665 722d 456e 636f 6469 6e67  ransfer-Encoding
00000a0: 3a20 4241 5345 3634 0a0a 596d 396b 6551  : BASE64..Ym9keQ
00000b0: 3d3d 0a                                  ==.
$


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-12 08:52 UTC] derick@php.net
PHP does not any headers or encodes the body at all, we simply pipe the data through the sendmail binary on your system so if  anything changes it is there where that happens.
 [2004-11-13 11:13 UTC] aflem26 at hotmail dot com
I have isolated the problem, and it is not with sendmail.  Please note how I tested this: 

$php -d sendmail_path=/bin/cat test.php
To: joe@test.com
Subject: subject
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: BASE64

Ym9keQ==



Kindest Regards
 [2004-11-14 04:38 UTC] aflem26 at hotmail dot com
In fact, this issue is related to an unscrupulous setting of mbstring.func_overload in php.ini in the RHEL 3.0 AS RPM for php.  This causes an mb_mail function to be called, which indeed encodes the body and adds the appropriate headers, potentially in conflict with use supplied headers.  

This causes many mail programs to fail, ie. Iloha Mail or Squirrel Mail
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC