[wp-trac] [WordPress Trac] #18521: Wp_mail function: email subject with multibyte chars is not encoded properly

WordPress Trac wp-trac at lists.automattic.com
Fri Aug 26 08:51:11 UTC 2011


#18521: Wp_mail function: email subject with multibyte chars is not encoded
properly
--------------------------+-----------------------------
 Reporter:  jetpackpony   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.2.1
 Severity:  major         |   Keywords:  needs-patch
--------------------------+-----------------------------
 '''Problem:'''
 When an email with multibyte characters (like Swedish é, å, etc.) in the
 subject is sent from Wordpress (using wp_mail), the subject of the email
 at the reciever end looks like this:
 =?UTF-8?Q?New_site_name_Site:_J=C3=A9t_inqsfzxb_p=C3=A5_?=
 =?UTF-8?Q?=C3=A9?=

 '''Reproduce:'''
 Create the new blog with a multibyte char in the blog title and then
 activate it.
 For example: go to /wp-content/wp-signup.php and create a new user. After
 that you will be asked to create a new blog. Create one and put some é and
 å characters in the blog title. After that you will recieve the first
 email (which should be ok), asking to activate the account. Activate it,
 then you will get the second email with the screwed subject.

 '''Reason:'''
 The reason is phpmailer class which double-encodes the email subject (only
 when sending mail using php mail() function though). The problem in these
 lines (wp-includes/class-phpmailer.php, taken from WP 3.2.1):
 (lines 657, 663, 671, 677)
 $rt = @mail($val,
 $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header,
 $params);
 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)),
 $body, $header, $params);
 $rt = @mail($val,
 $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header,
 $params);
 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)),
 $body, $header);
 The subject is first encoded with EncodeHeader function, and after that
 encoded again by mail() function itself.

 '''Fix suggestion:'''
 Since mail() function does proper encoding of subject, we don't need to
 encode it ourselves. So those lines should be replaced by:
 $rt = @mail($val, $this->Subject, $body, $header, $params);
 $rt = @mail($to, $this->Subject, $body, $header, $params);
 $rt = @mail($val, $this->Subject, $body, $header, $params);
 $rt = @mail($to, $this->Subject, $body, $header);
 I've tried this on my server, and it works well.

 '''Conclusion:'''
 Hope it will be fixed and included in the release soon. Although, i've
 found the good enough temporarily solution overloading wp_mail() with a
 plugin, but still would be nice to see the solution in the wordpress core.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18521>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list