|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36140 mb_encode_mimeheader not working properly
Submitted: 2006-01-24 12:15 UTC Modified: 2006-04-25 01:00 UTC
From: sugan_b at yahoo dot co dot in Assigned: hirokawa (profile)
Status: No Feedback Package: mbstring related
PHP Version: 5.1.2 OS: FC3
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-01-24 12:15 UTC] sugan_b at yahoo dot co dot in
 A small part of my application(using only PHP 5.1.2 and Apache 2.2.0) incorporates mailing functionality which uses "mb_encode_mimeheader()".I am using ISO-2202-JP charset but Multibyte characters written in ISO-2202-JP charset code are not sent to the  receiver correctly.

Reproduce code:

<!-- Start of index.php file -->
<meta http-equiv="Content-type" content="text/html; charset=EUC-JP"> <title>test</title> </head> <body> <form method="POST" action="send.php">
To??<input type="text" name="to" size="32" maxlength="128" value=""/><br>
Subject??<input type="text" name="subject" size="128" maxlength="12	8" value="???????? ?᡼????Subject??ʸ?????????Ƥ??ޤ??ޤ?"/><br> <br> <input type="submit" value="send" /> </form> </body> </html>
<!-- End of index.php file -->


<!-- Start of send.php file -->
function mailSend($from, $to, $subject, $message) {
    $encoded= mb_convert_encoding($subject, "ISO-2022-JP", "EUC-JP");
    $sub_mime = mb_encode_mimeheader($encoded, "ISO-2022-JP", "B", "\r\n");

    $body = mb_convert_encoding($message, "ISO-2022-JP", "EUC-JP");

    $mp = popen("/usr/sbin/sendmail -f $from $to", "w");
    fputs($mp, "Content-Transfer-Encoding: 7bit\r\n");
    fputs($mp, "From: ".$from."\r\n");
    fputs($mp, "To: ".$to."\r\n");
    fputs($mp, "Subject: ".$sub_mime."\r\n");
    fputs($mp, "MIME-Version: 1.0\r\n");
    fputs($mp, "X-Mailer: test php\r\n");
    fputs($mp, "Content-Type: text/plain; charset=\"iso-2022-jp\"");
    fputs($mp, "\r\n");
    fputs($mp, "$body\r\n");

<meta http-equiv="Content-Type" content="text/html;charset=EUC-JP">
  $from = "";
  $subject = $_POST['subject'];
  $to = $_POST['to'];
  $message = "???????Ƥ????ä????Ȥ????Τ餻???ޤ???\r\n";
  mailSend($from, $to, $subject, $message); ?>
Mail Sending has Completed.
<!-- End of send.php file -->

Actual result:
Actual Result:
The value of Subject field :
 &#21839;&#21512;&#12305; &#12513;&#12540;&#12523;&#12398;Subject&#12364;8;z2=$1$7$F$7$^$$$^$9

I have configured php using --enable-mbstring=all option.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-24 12:18 UTC] sugan_b at yahoo dot co dot in
The actual result obtained is:
&#12304;&#21839;&#21512;&#12305; &#12513;&#12540;&#12523;&#12398;Subject&#12364;8;z2=$1$7$F$7$^$$$^$9
 [2006-01-25 10:58 UTC]
Rui, can you check this out please?
 [2006-02-06 15:09 UTC]
Could you please check it by the simpler script ?

 mbstring.language = Japanese
 mbstring.internal_encoding = EUC-JP

$subject ="some euc-jp encoded japanese string.";
$encoded= mb_convert_encoding($subject, "ISO-2022-JP", "EUC-JP");
$sub_mime = mb_encode_mimeheader($encoded, "ISO-2022-JP", "B","\r\n");
echo $sub_mime;
It works well or  not ?
If the result is a correct MIME encoded string, 
mb_encode_mimeheader() work fine.

 [2006-02-17 11:15 UTC] sugan_b at yahoo dot co dot in
Sorry for the late response.
This is my understanding. Please correct me if i am wrong.
The mb_encode_mimeheader function is doing base64 encoding process in mbfilter.c. base64 encoding encodes from the front by each 3bytes of the object character and if the
length of character has no more 3bytes, it converts the rest 1 or 2 bytes into "=", value "0x3d". mb_encode_mimeheader is actually doing this process but According to RFC2047, A long
word exceeds 75bytes should be expressed by multiple lines.  mb_encode_mimeheader does not care about this line separating action and thus the bit value of encoded character is misencoded and sent to mail receiver incorrectly.

I think that is the reason for  the subject value to get garbled.
 [2006-04-10 13:07 UTC]
Rui, this might be good candidate for fixing. :)
 [2006-04-17 15:23 UTC]
Please test this code.
The string of first argument should be encoded in the internal encoding (EUC-JP in this case.) .
You should not convert the string into ISO-2022-JP
using mb_convert_encoding()

 mbstring.language = Japanese
 mbstring.internal_encoding = EUC-JP

$msg ="some euc-jp encoded japanese string.";
$sub_mime = mb_encode_mimeheader($msg,"ISO-2022-JP","B","\r\n");
echo $sub_mime;

 [2006-04-25 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 02:01:26 2019 UTC