473,411 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

mail(): carriage returns get scrambled

I wrote a custom class that uses mail() to send messages. My class
takes care that all lines end in \r\n as required by RFCs.

I have two Red Hat 9 servers (development + production). My development
server works fine; however, I've noticed that in my production server
extra line ending chars are added randomly to outgoing messages. I
didn't notice until now because Outlook handles it fine. On the
contrary, most other mail clients think these extra line feeds are
empty lines. As a result, headers pop into message body and message
body itself gets extra blanks line.

As I said, it looks random to me--I can't find any pattern:

Dear customer,\r\n
\r\n

.... turns into:

Dear customer,\n\n
\n\n

I looks like \r is replaced by \n... But:

Content-Type: text/plain; charset=iso-8859-1\r\n
Content-Transfer-Encoding: 8bit\r\n

.... turns into:

Content-Type: text/plain; charset=iso-8859-1\r\n
\r\n
Content-Transfer-Encoding: 8bit\n\n

(the same input \r\n gets two different outputs).

I check both body and custom headers just before calling mail():

echo str_replace(array("\n", "\r"), array("\\n\n", "\\r"), $headers);
echo str_replace(array("\n", "\r"), array("\\n\n", "\\r"), $body);
mai(.....);

At this point, everything's OK.

My first candidate was mod_security, yet disabling it makes no change.
We don't have a virus scanner. Mail server is postfix.

Do you have any hint??

Aug 2 '06 #1
1 1621
kAlvaro wrote:
I wrote a custom class that uses mail() to send messages. My class
takes care that all lines end in \r\n as required by RFCs.

I have two Red Hat 9 servers (development + production). My development
server works fine; however, I've noticed that in my production server
extra line ending chars are added randomly to outgoing messages. I
didn't notice until now because Outlook handles it fine. On the
contrary, most other mail clients think these extra line feeds are
empty lines. As a result, headers pop into message body and message
body itself gets extra blanks line.

As I said, it looks random to me--I can't find any pattern:

Dear customer,\r\n
\r\n

... turns into:

Dear customer,\n\n
\n\n

I looks like \r is replaced by \n... But:

Content-Type: text/plain; charset=iso-8859-1\r\n
Content-Transfer-Encoding: 8bit\r\n

... turns into:

Content-Type: text/plain; charset=iso-8859-1\r\n
\r\n
Content-Transfer-Encoding: 8bit\n\n

(the same input \r\n gets two different outputs).

I check both body and custom headers just before calling mail():

echo str_replace(array("\n", "\r"), array("\\n\n", "\\r"), $headers);
echo str_replace(array("\n", "\r"), array("\\n\n", "\\r"), $body);
mai(.....);

At this point, everything's OK.

My first candidate was mod_security, yet disabling it makes no change.
We don't have a virus scanner. Mail server is postfix.

Do you have any hint??
Hi,

Not sure about the RFC, but I always just used the \n alone, without the \r,
and that never gave any troubles. :-/
Maybe give that a try.

just my 2 cent

Regards,
Erwin Moller
Aug 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jim Seymour | last post by:
I have a contact form that uses PHP's mail() function. It recently came to my attention that (some?) MS-Windows mail servers may not properly process data given to the mail() function that's only...
4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
2
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this...
2
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost...
8
by: TheDude5B | last post by:
Hi, I have some data which is stored in my MySQL database as TEXT. when the data is entered in, it has some carriage returns in it, and this can be seen when querying the data using MySQL Query...
6
by: jerrygarciuh | last post by:
Hi folks, HELP!!!! My habitual use of mail() is causing me some grief. I am having slightly different results depending on the server I use but the gist is that mail() is returning 1, and I...
7
by: mattrapoport | last post by:
I have a page with a div on it. The div displays a user comment. When the user logs into this page, their current comment is pulled from a db and displayed in the div. The user can edit the...
0
by: Rey | last post by:
Howdy all. Am using visual web developer 2005 (vb), xp pro sp2. In testing of the system.net.mail to send email from an aspx page where I'm pulling the email contents from a textbox, find that...
0
by: markus.shure | last post by:
Hi, I'm noticed a problem testing a JAX-WS client with a WSE server. The JAX-WS client adds carriage returns to a SOAP header element that is signed. This causes the WSE server to raise an...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.