php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33709 Problems with mail and str_replace
Submitted: 2005-07-14 23:51 UTC Modified: 2005-07-15 08:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jjohnson at salesteamautomation dot com Assigned:
Status: Not a bug Package: Mail related
PHP Version: 4.4.0 OS: Windows XP
Private report: No CVE-ID: None
 [2005-07-14 23:51 UTC] jjohnson at salesteamautomation dot com
Description:
------------
We're having a problem with mail and str_replace.  If we use str_replace on certain emails before sending them, we get extra characters in the email that is sent.  Right before sending, the email looks fine.  When it is received, however, it has extra characters.  If str_replace is not used, the received email does not have extra characters.

Reproduce code:
---------------
$content_template = '<html><head></head><body><DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Web only - $1,100 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Phone only - $1,300 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Both - $1,500 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="TEXT-INDENT: 0.5in"><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">*There is a one time set-up fee of $499 which we will waive with a three year agreement.</SPAN></FONT></body></html>';
$content = "?         Web only - $1,100 per year ".
"?         Phone only - $1,300 per year ".
"?         Both - $1,500 per year ".
"*There is a one time set-up fee of $499 which we will waive with a three
year agreement. ";
class EmailTest{
	function EmailTest($email_from, $email_to, $subject, $content_template, $content){
		$this->email_from       = $email_from;
		$this->email_to         = $email_to;
		$this->subject          = $subject;
		$this->content          = $content;
		$this->content_template = $content_template;
	}
}
$email =& new EmailTest( "jjohnson@salesteamautomation.com", "jjohnson@salesteamautomation.com", "SilentWhistle Follow-up", $content_template, $content);
$email->content_template = str_replace("\n",'',$email->content_template);
$email->content = str_replace('', '', $email->content_template);
$email->content = $email->content_template;
$header = "MIME-Version: 1.0\nContent-Type: text/html; charset=iso-8859-1\n";
$result = mail($email->email_to, $email->subject, $email->content, $header, '');

Expected result:
----------------
This is the expected email:

?         Web only - $1,100 per year 
?         Phone only - $1,300 per year 
?         Both - $1,500 per year 
*There is a one time set-up fee of $499 which we will waive with a three year agreement.

This is the html from the expected email:

<html><head></head><body><DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Web only - $1,100 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Phone only - $1,300 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Both - $1,500 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="TEXT-INDENT: 0.5in"><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">*There is a one time set-up fee of $499 which we will waive with a three year agreement.</SPAN></FONT></body></html>

Actual result:
--------------
This is the received email:

?         Web only - $1,100 per year 
?  ;        Phone only - $1,300 per year 
?         Both - $1,500 per year 
*There is a one time set-up fee of $499 which we will waive with a three year agreement. 

This is the html from the received email:

<html><head></head><body><DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Web only - $1,100 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp
 ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Phone only - $1,300 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Both - $1,500 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="TEXT-INDENT: 0.5in"><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FO
 NT-FAMILY: Arial">*There is a one time set-up fee of $499 which we will waive with a three year agreement.</SPAN></FONT></body></html>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-14 23:59 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

Please provide a *short* and *readable* reproduce script. Thanks.
 [2005-07-15 00:58 UTC] jjohnson at salesteamautomation dot com
Here's the shortest script I can create to replicate the bug.  The code is not that long, but it seems to be dependent on the data.  I shortened the data as much as I could.

$breaks = '
<html><head></head><body>
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Phone only - $1,300 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Both - $1,500 per year<o:p></o:p></SPAN></FONT></SPAN> 
</body></html>
';
$works = '
<html><head></head><body>
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Phone only - $1,300 per year<o:p></o:p></SPAN></FONT></SPAN> 
<DT class=MsoNormal style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo6; tab-stops: list .75in"><FONT face=Symbol size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"><SPAN style="mso-list: Ignore">?<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN></FONT><SPAN dir=ltr><FONT face=Arial color=black size=2><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Both - $1,500 per year<o:p></o:p></SPAN></FONT></SPAN> 
</body></html>
';
$breaks = str_replace("\n",'',$breaks);
$header = "MIME-Version: 1.0\nContent-Type: text/html; charset=iso-8859-1\n";
$result = mail("jjohnson@salesteamautomation.com", 'breaks', $breaks, $header, '');
$result = mail("jjohnson@salesteamautomation.com", 'works', $works, $header, '');
 [2005-07-15 01:00 UTC] jjohnson at salesteamautomation dot com
Just a note on the above comment.  str_replace is what causes corrupted emails.  The content looks fine on the sender end, but the receiver end has problems.
 [2005-07-15 01:34 UTC] jjohnson at salesteamautomation dot com
This is also a problem with version 4.4.0.
 [2005-07-15 08:24 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Works just fine here. Ask somewhere else what's wrong with your "HTML".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 01:01:28 2024 UTC