Problems with mime encoding of Japanese Characters in Subject and 'From:', 'Reply-to:', ... fields.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, 

--- note ---
I sent a similar message already to php-i18n - but this list seems
not to be used very much (20 messages this year) so I am posting it
here again...
------------

I try to send messages written in Japanese (Kana/Kanji) with php.

Everything works fine - only when the subject (or the name of the
sender) becomes longer, there seems to be something wrong with the
encoding: Neither my nor the mail reader of other (Japanese) friends 
decodes the mime string. At the place of the Japanese Characters, 
the mime string itself is displayed in the subject (to, reply to) 
field.

As this doesn't happen for other Japanese emails with even longer
subjects, I suppose I did something wrong ... but what?

Here how I convert the subject (the name is converted using the same
method and the sources are saved in UTF-8 using emacs):

  $subjectJIS  = mb_convert_encoding($subject, "ISO-2022-JP", "AUTO");
  $subjectMIME = mb_encode_mimeheader($subjectJIS, "ISO-2022-JP", "B");
  ...snip...
  mail($to, $subjectMIME, $bodyJIS, $headers);

Here part of the message as it is displayed by my mail program:

  From:
=?ISO-2022-JP?B?GyRCJCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7?==?ISO-2022-JP?B?eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3ob?=(B <d.bollmann@xxxxxxxxxxxx>
  ...snip...
  Subject:
=?ISO-2022-JP?B?GyRCJCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7?= =?ISO-2022-JP?B?eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3ob?= (B
  ...snip...
  
  かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字かな漢
字かな漢字

And here part of the mail text itself:

  ...snip...
  Subject:

=?ISO-2022-JP?B?GyRCJCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7?=

=?ISO-2022-JP?B?eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3ob?=
  	=?ISO-2022-JP?B?KEI=?=
  MIME-Version: 1.0
  From:
=?ISO-2022-JP?B?GyRCJCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7?= =?ISO-2022-JP?B?eiQrJEo0QTt6JCskSjRBO3okKyRKNEE7eiQrJEo0QTt6JCskSjRBO3ob?= =?ISO-2022-JP?B?KEI=?= <d.bollmann@xxxxxxxxxxxx>
  ...snip...
  Content-Type: text/plain; charset=ISO-2022-JP
  ...snip...
  
  かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字かな漢
字かな漢字

Here a part of another (spam) mail which is correctly displayed by my
mail program:

  MIME-Version: 1.0
  Subject:
=?ISO-2022-JP?B?GyRCIXolXSUkJXMlSBsoQjEwGyRCR1whdUF3TkEbKEI=?=
  	=?ISO-2022-JP?B?GyRCTDVOQSF6GyhCMSwwMDAbJEIxXyU4JWUbKEI=?=
  	=?ISO-2022-JP?B?GyRCJSglaiE8Qmc9ODlnISohWjNaRTchWxsoQg==?=
  	=?ISO-2022-JP?B?GyRCIUobKEIyMDA4LzAzLzE5?= =?ISO-2022-JP?B?KQ==?=
  From: =?ISO-2022-JP?B?GyRCM1pFNztUPmwlOCVlJSglaiE8ISYlIhsoQg==?=
=?ISO-2022-JP?B?GyRCJS8lOyU1JWohPCVLJWUhPCU5GyhC?=
<jewelry@xxxxxxxxxxxxxxxxxxxxxxx>
  
Displayed as:

  From: 	楽天市場ジュエリー・アクセサリーニュース
<jewelry@xxxxxxxxxxxxxxxxxxxxxxx>
  ...snip...
  Subject: 	★ポイント10倍&送料無料★1,000円ジュエリー大集合!【楽天】
(2008/03/19)
  
If anybody can explain me the problem I would be most grateful :)

Thanks, Dietrich


---
PS: I appended a little example program which produces the problem.

The same program works correctly when using the following values:

  $subject = "かな漢字";
  $senderName = "かな漢字";

Thanks for your help :)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
     <head>
     <meta http-equiv="content-type" content="text/html;
charset=UTF-8" />
     <title>Contact Me</title>
     </head>
     <body>

     <h1>かな漢字</h1>

     <?php # Script 10.1 - email.php

function sendEmail($recipientEmailAddress, $subject, $body, $senderName,
$senderEmailAddress) {
    
    // set current language to Japanese
    mb_language("ja");

    // encode subject
    // - first using JIS (ISO-2022-JP)
    // - after encoding the resulting JIS string with the MIME header
encoding scheme
    $subjectJIS  = mb_convert_encoding($subject, "ISO-2022-JP", "AUTO");
    $subjectMIME = mb_encode_mimeheader($subjectJIS, "ISO-2022-JP",
"B");

    // encode the name of the sender
    // - first using JIS (ISO-2022-JP)
    // - after encoding the resulting JIS string with the MIME header
encoding scheme
    $senderNameJIS  = mb_convert_encoding($senderName, "ISO-2022-JP",
"AUTO");
    $senderNameMIME = mb_encode_mimeheader($senderNameJIS,
"ISO-2022-JP", "B");

    // encode body
    // - using JIS (ISO-2022-JP)
    // - the used coding system had to be specified in the
Content-Type/charset header:
    //   Content-Type: text/plain; charset=ISO-2022-JP
    $bodyJIS = mb_convert_encoding($body, "ISO-2022-JP", "AUTO");

    // formatting the sender string
    $senderMIME = sprintf("%s <%s>", $senderNameMIME,
$senderEmailAddress);

    // formatting the mime header
    $headers  = "MIME-Version: 1.0\n" ;
    $headers .= sprintf("From: %s\n",     $senderMIME);
    $headers .= sprintf("Reply-To: %s\n", $senderMIME);
    $headers .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
   
    // send encoded mail
    $result = mail($recipientEmailAddress, $subjectMIME, $bodyJIS,
$headers);

    // return result
    return $result;
 }

$to                 = "snip@xxxxxxxxx";
$subject            = "かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字
かな漢字かな漢字かな漢字かな漢字";
$body               = "かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字
かな漢字かな漢字かな漢字かな漢字";
$senderName         = "かな漢字かな漢字かな漢字かな漢字かな漢字かな漢字
かな漢字かな漢字かな漢字かな漢字";
$senderEmailAddress = "snip@xxxxxxxxx";
     
// send the email
sendEmail($to, $subject, $body, $senderName, $senderEmailAddress);
	    
?>

</body>
</html>





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux