Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.12

Bug #12216 Incorrect Mail_mime::headers() behaviour (russian text, utf8)
Submitted: 2007-10-10 11:36 UTC
From: chewie Assigned: cipri
Status: Closed Package: Mail_Mime (version 1.5.2)
PHP Version: 5.2.4 OS: linux
Roadmaps: 1.5.3    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 18 - 10 = ?

 
 [2007-10-10 11:36 UTC] chewie (Alexey Ka)
Description: ------------ Hello, I have an script which sends emails with Mail/mime.php. I need to send mails with russian text and russian subject in utf8. When I am trying to pass array with headers (it contains subject), in the result I am getting empty value for subject, but when I am working with english text in utf8, it shows value normally. Test script: --------------- <?php $crlf = "\n"; $mimeObject = new Mail_mime($crlf); $hdrs = array( 'Subject' => 'Регистрация' ); var_dump($hdrs); $hdrs = $mimeObject->headers($hdrs); var_dump($hdrs); ?> Expected result: ---------------- array 'MIME-Version' => string '1.0' 'Subject' => string 'Регистрация' 'Content-Transfer-Encoding' => string 'quoted-printable' 'Content-Type' => string 'text/html; charset="utf8"' Actual result: -------------- array 'MIME-Version' => string '1.0' 'Subject' => string '' 'Content-Transfer-Encoding' => string 'quoted-printable' 'Content-Type' => string 'text/html; charset="utf8"'

Comments

 [2007-10-11 22:47 UTC] cipri (Cipriano Groenendal)
The subject you use contains HTML characters. You need to supply the actual text in UTF8 code if you want it translated in the email subject.
 [2007-10-12 08:34 UTC] chewie (Alexey Ka)
It doesn't contain any html character, it's just russian string.
 [2007-10-12 12:42 UTC] cipri (Cipriano Groenendal)
Please send an example email to cipri@php.net with a subject like that, and I'll have a look.
 [2007-10-12 13:30 UTC] chewie (Alexey Ka)
Seems to be found an reason... When I am trying to send letter with such headers: $hdrs = array('to' => 'aa@bb.cc', 'from' => 'aa@bb.cc', 'subject' => 'russian text here'); the letter subject comes empty... but when I have something like this - $subject = 'russian text here'; $hdrs = array('to' => 'aa@bb.cc', 'from' => 'aa@bb.cc', 'subject' => $subject); letter comes normally with russian text in it's subject... Am i need to send you emails to check or ... ?
 [2008-06-13 21:24 UTC] lrajlich (Luke Rajlich)
I am also seeing this problem... Sometimes we have non-ascii characters in our subject line and the ->headers function does not seem to properly handle this case. It breaks the email headers and the email reader (in this case, gmail) no longer thinks it is seeing an mime / html email but spits out the markup as text. I use the following code: $headers = array( 'From' => "$fromName <$fromEmail>", 'To' => $email, 'Subject' => $subject ); Log::writeToLog("testLog","before mime->headers: " . print_r($headers,TRUE)); //create a mime email message to send $mime = new Mail_mime("\n"); $mime->setHTMLBody($message); $message = $mime->get(); $headers = $mime->headers($headers); Log::writeToLog("testLog","after mime->headers: " . print_r($headers,TRUE)); and I see the following in my log... 14:17:10 06/13/08 ident [debug] before mime->headers: Array ( [From] => XXXX [To] => XXXX [Subject] => Luke<E2><99><A5><E2><99><A0>~<E2><84><A2><E2><99><AB> sent you a message! ) 14:17:10 06/13/08 ident [debug] after mime->headers: Array ( [MIME-Version] => 1.0 [From] => XXXX [To] => XXXX [Subject] => =?ISO-8859-1?Q?Luke=E2=99=A5=E2=99=A0~=E2=84=A2=E2=99=AB=20=20s?= =?ISO-8859-1?Q?ent=20you=20a=20message!?= [Content-Transfer-Encoding] => quoted-printable [Content-Type] => text/html; charset="ISO-8859-1" )
 [2008-06-27 11:06 UTC] jsandeo (Jose Sandeo)
I'm having the same problem. The following source code is iso-8859-01 ################################### $subject = "This is just a subject line, which goes on for a few characters, and on and on"; $cabeceras = array_merge(array('From' => $from), $array_to, array('Subject' => $subject)); $body = $mime->get(); $hdrs = $mime->headers($cabeceras); print_r($cabeceras); print_r($hdrs); exit; ################################### Output: Array ( [From] => IberGour <info@ibergour.com> [To] => info@ibergour.com [Cc] => jsandeo@evolucy.com [Subject] => This is just a subject line, which goes on for a few characters, and on and on ) Array ( [MIME-Version] => 1.0 [From] => IberGour <info@ibergour.com> [To] => info@ibergour.com [Cc] => jsandeo@evolucy.com [Subject] => This is just a subject line, which goes on for a few characters, and on and on [Content-Transfer-Encoding] => 7bit [Content-Type] => text/plain; charset="ISO-8859-1" ) Whereas the following won't work: ################################### $subject = "This is just a subject line España, which goes on for a few characters, and on and on"; $cabeceras = array_merge(array('From' => $from), $array_to, array('Subject' => $subject)); $body = $mime->get(); $hdrs = $mime->headers($cabeceras); print_r($cabeceras); print_r($hdrs); exit; ################################# Output: Array ( [From] => IberGour <info@ibergour.com> [To] => info@ibergour.com [Cc] => jsandeo@evolucy.com [Subject] => This is just a subject line España, which goes on for a few characters, and on and on ) Array ( [MIME-Version] => 1.0 [From] => IberGour <info@ibergour.com> [To] => info@ibergour.com [Cc] => jsandeo@evolucy.com [Subject] => =?ISO-8859-1?Q?This=20is=20just=20a=20subject=20line=20Espa=F1a?= =?ISO-8859-1?Q?,=20which=20goes=20on=20for=20a=20few=20characters,=20an?= =?ISO-8859-1?Q?d=20on=20and=20on?= [Content-Transfer-Encoding] => 7bit [Content-Type] => text/plain; charset="ISO-8859-1" ) If I send this last message to a gmail account, it displays all messed up, the subject being truncated at the second =?, and the rest of the headers being displayed inside the text of the body.
 [2008-08-15 23:36 UTC] m0r1arty (Nikolay Nezhinsky)
$message=new Mail_mime(); $message->_build_params['html_charset']='UTF-8'; $message->_build_params['text_charset']='UTF-8'; $message->_build_params['head_charset']='UTF-8'; $message->_build_params['head_encoding']='base64'; /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
 [2008-11-11 14:10 UTC] warl0rd (Paulo Serrão)
The problem is the extras '=?ISO-8859-1?Q?' (or other enconding code) and '=?' that appear several times in the subject line after performing: $headers = $mime->headers($headers); A quick fix is to overwrite the $headers['subject'] with just one '=?ISO-8859-1?Q?' at the start and the '=?' in the end. $headers['subject']='=?ISO-8859-1?Q?'.$subject.'=?';
 [2009-08-25 12:05 UTC] cweiske (Christian Weiske)
-Status: Feedback +Status: Verified
 [2009-12-21 14:52 UTC] alec (Aleksander Machniak)
-Status: Verified +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.
 [2010-03-03 12:31 UTC] roger (Arthur Blomnik)
this bug is still remaining. I try to send letters with Russian text in subject. Some of characters are not printable and displayed as ??. I used this part of code: $message->_build_params['head_encoding']='base64'; and amount of non-printable characters was decreased, but still ramaining. Without this code subject was: Subject: =?utf-8?Q?0KHQutGA0LjQv9GCINC+0YLQv9GA0LDQstC60Lgg0L/QuNGB0LXQ?= =?utf-8?B?vCAoMC4xLjMuMSk=?= with "head_encoding = base64" subject is Subject: =?utf-8?B?0KHQutGA0LjQv9GCINC+0YLQv9GA0LDQstC60Lgg0L/QuNGB0LXQ?= =?utf-8?B?vCAoMC4xLjMuMSk=?= is it bug? This is my mail script (body and subject contain Russian text. Body displaying perfect!) $text = '????????? ?????? ??????'; $html = '<html><body><h1>HTML ?????? ??????</h1><img src="header-logo2.jpg" alt="Header Logo" /><p>?????? ?????????? ? ??????? ?????????? PEAR</p></body></html>'; $file = $abs_path.'/images/header-logo2.jpg'; $crlf = "\r\n"; $hdrs = array( 'From' => 'webmaster@vubor.org.ua', 'Subject' => '?????? ???????? ????? (0.1.3.1)' ); $mime = new Mail_mime($crlf); $get_param = array( "text_encoding" => "base64", "html_encoding" => "base64", "head_charset" => "utf-8", "text_charset" => "utf-8", "html_charset" => "utf-8" ); $mime->_build_params['head_encoding']='base64'; $mime->setTXTBody($text); $mime->addHTMLImage($file, 'image/jpeg'); $mime->setHTMLBody($html); $body = $mime->get($get_param); $hdrs = $mime->headers($hdrs); $mail =& Mail::factory('mail'); $status = $mail->send('blomnik@gmail.com', $hdrs, $body); if (PEAR::isError($status)) { print("ERROR: Mail not sent!"); }
 [2011-10-25 12:21 UTC] power_wong (Power Wong)
The key setting should be the 'head_charset'. I quoted my working code at below: $mime = new Mail_mime; $mime->setTXTBody($text); $mime->setHTMLBody($html_message); $mimeparams=array(); $mimeparams['text_encoding']="7bit"; $mimeparams['text_charset']="UTF-8"; $mimeparams['html_charset']="UTF-8"; $mimeparams['head_charset']="UTF-8"; $body = $mime->get($mimeparams); $headers = $mime->headers($headers); $page_content = "Mail now."; $mail =& Mail::factory('mail');