|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47868 Special apostrophe character stripped from subject
Submitted: 2009-04-01 21:30 UTC Modified: 2014-01-23 18:48 UTC
Avg. Score:2.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: cconnors at online-buddies dot com Assigned:
Status: Not a bug Package: Mail related
PHP Version: 5.2.9 OS: win32 only - XPSP2
Private report: No CVE-ID: None
 [2009-04-01 21:30 UTC] cconnors at online-buddies dot com
The following character (?) is automatically stripped from a subject, but not the body using mail().

Quick fix is...

$subj = str_replace('?', '\'', $template->getSubject());

But it's not EXACTLY the same character.

I've played around with the header, and cannot get it to work with UTF-8.

Reproduce code:
header = "From: ". 'noreply' . 
	    " <" . '' . ">\n" . 
	    "Reply-To: " . '' . "\n" . 
	    "Content-type: text/plain; charset=UTF-8\n\n";

mail('', 'french d?avoir' , 'french d?avoir', $header);

Expected result:
Should get a message with:

subject: french d?avoir
body: french d?avoir

Actual result:
Actually get: 

subject: french davoir
body: french d?avoir


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-06 20:36 UTC] astewart at online-buddies dot com
This is not a bug.

The header field must be encoded if you want non-ASCII characters in it, as in:

Subject: =?iso-8859-1?Q?french d=92avoir?=
 [2012-07-06 20:38 UTC] astewart at online-buddies dot com
Actually, that's not ISO-8859-1, that's Windows-1252:

    Subject: =?Windows-1252?Q?french d=92avoir?=

Which illustrates the problem neatly: You have to know the character encoding in 
use to make sense of non-ASCII characters.
 [2014-01-23 15:22 UTC] cmbecker69 at gmx dot de
Hm, the bug description is missing, but it seems astewart is
right that this is *not* *a* *bug*.
 [2014-01-23 18:48 UTC]
-Status: Open +Status: Not a bug
 [2014-01-23 18:48 UTC]
The Wayback Machine has an archived copy with the description.

mail() doesn't know what encoding the string you gave for the subject is so stripping out bytes that aren't allowed in 7-bit ASCII is IMO a fair resolution. You can easily encode the subject yourself with

  "=?iso-8859-1?Q?" . quoted_printable_encode("french d\x92avoir") . "?="
(if it's ISO-8859-1 encoding, otherwise you'll need a different string)

The relevant RFC is 2047

Or, you know, use a mail library that does all this stuff for you.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 00:01:26 2023 UTC