473,386 Members | 1,883 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,386 software developers and data experts.

MS-Windows mail servers and PHP's mail() function

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
newline-terminated.

The mail() function takes up to five parameters:

mail(recipient, subject, message, [headers [,parameters]])

The ones of interest here are the first four. The questions are
these:

1. Since recipient and subject are not multi-line, and, from the
web form, don't even contain newlines, is it safe to assume
they need neither newlines nor carriage-returns?

2. The message, from the web form, contains newlines. I assume
all newlines need carriage-returns inserted in front of them?

3. The headers are created, in the web form processing, by
appending newline-terminated strings to a variable (e.g.:
headers .= "blah: yadda\n";). I presume that this string
likewise needs carriage-returns inserted before the newlines?

4. I've seen mention of problems with "hanging carriage-returns."
I presume that simply means there should be no line, blank or
otherwise, that contains a carriage-return w/o an accompanying
newline?

Assuming all the above to be true, my four parameters would look like:

recipient: "so******@example.com"
subject: "Some subject"
message: "Some message\r\ntext\r\ngoes here\r\n"
headers: "Header1: foo\r\nHeader2: bar\r\nHeader3: baz\r\n"

Is the above what (some?) MS-Windows mail servers want to see?

TIA,
Jim
--
Jim Seymour | PGP Public Key available at:
| http://www.uk.pgp.net/pgpnet/pks-commands.html
|
| http://jimsun.LinxNet.com
Jul 17 '05 #1
7 2595
Jim Seymour wrote:
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
newline-terminated.

The mail() function takes up to five parameters:

mail(recipient, subject, message, [headers [,parameters]])

The ones of interest here are the first four. The questions are
these:

1. Since recipient and subject are not multi-line, and, from the
web form, don't even contain newlines, is it safe to assume
they need neither newlines nor carriage-returns?

2. The message, from the web form, contains newlines. I assume
all newlines need carriage-returns inserted in front of them?

3. The headers are created, in the web form processing, by
appending newline-terminated strings to a variable (e.g.:
headers .= "blah: yadda\n";). I presume that this string
likewise needs carriage-returns inserted before the newlines?

4. I've seen mention of problems with "hanging carriage-returns."
I presume that simply means there should be no line, blank or
otherwise, that contains a carriage-return w/o an accompanying
newline?

Assuming all the above to be true, my four parameters would look like:

recipient: "so******@example.com"
subject: "Some subject"
message: "Some message\r\ntext\r\ngoes here\r\n"
headers: "Header1: foo\r\nHeader2: bar\r\nHeader3: baz\r\n"

Is the above what (some?) MS-Windows mail servers want to see?

TIA,
Jim


it is not just "MS-Windows" mail servers, the CR/LF is a part of the SMTP RFC
for email headers. There have been several discussions in this group about this
issue in the past, rather trying to remember all of the nuances of the
discussions, I would recommend a search for WNT, PHP, mail and take a look at
the docs.

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #2
In article <cu*****************@newssvr22.news.prodigy.com> ,
Michael Austin <ma*****@firstdbasource.com> writes:
[snip]

it is not just "MS-Windows" mail servers, the CR/LF is a part of the
SMTP RFC
for email headers.
I'm aware of that. But my mail servers, at least, seem to just
"handle it" when I use the mail() function. (Which injects email
into the local MTA's queue via the "sendmail" command and therefor
isn't using SMTP, btw.) I don't know that *all* 'nix-based MTAs do
that, but mine does. Furthermore: From my discussion with my friend
and colleague: Apparently so do some (most?) MS-Win-based MTAs. He
has a .NET-based contact form that was working just fine, until along
came somebody for whom it did not work (mail simply went into a black
hole - no error return or anything) until he inserted
carriage-returns.
There have been several discussions in this group
about this
issue in the past, rather trying to remember all of the nuances of the
discussions,
I searched my current news spool for "[Ww]indows.*[Mm]ail" and
"[Mm]ail.*[Ww]indows", w/o success.
I would recommend a search for WNT, PHP, mail
Okay. I'll try those search terms in Google Groups. Thanks.
and take a
look at
the docs.


I looked at the docs. My questions were based on what I gleaned from
the docs and the associated follow-up comments. I'm just trying to
make sure, as best as possible, I have it as right, since I have no
MS-Win server to test it on and no idea what MS-Win-based MTA(s) need
the carriage-returns, even if I did.

Thanks for the follow-up.

--
Jim Seymour | PGP Public Key available at:
WARNING: The "From:" address | http://www.uk.pgp.net/pgpnet/pks-commands.html
is a spam trap. DON'T USE IT! |
Use: js******@LinxNet.com | http://jimsun.LinxNet.com
Jul 17 '05 #3
Hello,

On 07/24/2004 01:13 PM, Jim Seymour wrote:
I looked at the docs. My questions were based on what I gleaned from
the docs and the associated follow-up comments. I'm just trying to
make sure, as best as possible, I have it as right, since I have no
MS-Win server to test it on and no idea what MS-Win-based MTA(s) need
the carriage-returns, even if I did.


Depending on the PHP version that you use, your deliveries may be
affected by bugs of the PHP mail() function.

You may want to try this class that provides some workarounds to the PHP
mail function bugs. It comes with several sub-classes that implement
alternative delivery methods to using the mail function. It also comes
with wrapper functions named smtp_mail() and sendmail_mail() functions
that emulate the mail() function except that they deliver the messages
via the sendmail program or via SMTP.

http://www.phpclasses.org/mimemail
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #4
Hello,

On 07/24/2004 01:13 PM, Jim Seymour wrote:
I looked at the docs. My questions were based on what I gleaned from
the docs and the associated follow-up comments. I'm just trying to
make sure, as best as possible, I have it as right, since I have no
MS-Win server to test it on and no idea what MS-Win-based MTA(s) need
the carriage-returns, even if I did.


Depending on the PHP version that you use, your deliveries may be
affected by bugs of the PHP mail() function.

You may want to try this class that provides some workarounds to the PHP
mail function bugs. It comes with several sub-classes that implement
alternative delivery methods to using the mail function. It also comes
with wrapper functions named smtp_mail() and sendmail_mail() functions
that emulate the mail() function except that they deliver the messages
via the sendmail program or via SMTP.

http://www.phpclasses.org/mimemessage
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #5
In article <41**************@acm.org>,
Manuel Lemos <ml****@acm.org> writes:
Hello,

On 07/24/2004 01:13 PM, Jim Seymour wrote:
I looked at the docs. My questions were based on what I gleaned from
the docs and the associated follow-up comments. I'm just trying to
make sure, as best as possible, I have it as right, since I have no
MS-Win server to test it on and no idea what MS-Win-based MTA(s) need
the carriage-returns, even if I did.
Depending on the PHP version that you use, your deliveries may be
affected by bugs of the PHP mail() function.


I've used the code I wrote under everything from PHP 4.2.3 to 4.3.8,
with Apache from at least 1.3.27 through 1.3.31, on various releases
of Linux, Sparc Solaris and FreeBSD, with sendmail, qmail, and various
revisions of Postfix for MTAs.

You may want to try this class that provides some workarounds to the PHP
mail function bugs. [snip]


Thanks, Manuel, but good ol' mail() is working fine for me, on the
platforms I choose to use. If mail() was so b0rk3d as to fail to
work correctly and reliably on my platforms-of-choice, I wouldn't be
using PHP. Period. If I can do *minor* code-changes to make my work
(more) usable by my MS-Win-using brethren: I'm more than happy to do
so. But *minor* is as far as I'm willing to go.

Thanks for the follow-up.

--
Jim Seymour | PGP Public Key available at:
WARNING: The "From:" address | http://www.uk.pgp.net/pgpnet/pks-commands.html
is a spam trap. DON'T USE IT! |
Use: js******@LinxNet.com | http://jimsun.LinxNet.com
Jul 17 '05 #6
In article <cu*****************@newssvr22.news.prodigy.com> ,
Michael Austin <ma*****@firstdbasource.com> writes:
Jim Seymour wrote:
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
newline-terminated.
[snip]
it is not just "MS-Windows" mail servers, the CR/LF is a part of the
SMTP RFC
for email headers. There have been several discussions in this group
about this
issue in the past, rather trying to remember all of the nuances of the
discussions, I would recommend a search for WNT, PHP, mail and take a
look at
the docs.


Unfortunately, I wasn't able to turn up much in the way of useful
information by searching Google Groups with strings such as "WNT
mail," "WINNT mail," or "WIN32 mail." But this URL

http://us2.php.net/manual/en/function.mail.php

had, on a second reading, all that I needed. (I think.) From that,
it looks like all I have to do is make sure the additional_headers
have cr/lf at the end of each header line, save the last header line,
which must have neither a cr nor a lf.

My additional_headers are added here-and-there, throughout the code,
to a variable named $addlHeaders. Each header line is added with a
trailing newline. So, just before I call mail, I have this bit of
code:

// MS-Win mail servers want crlf and *don't* want a trailing pair
if(PHP_OS == "WIN32" || PHP_OS == "WINNT") {
// It seems we only need do this with the "additional headers,"
// but we're set up here to easily add other mail() variables.
foreach (array('addlHeaders') as $foo) {
$$foo = preg_replace("/\n$/", "", $$foo);
$$foo = preg_replace("/\n/", "\r\n", $$foo);
}
}

Thanks to all for the follow-ups.

--
Jim Seymour | PGP Public Key available at:
WARNING: The "From:" address | http://www.uk.pgp.net/pgpnet/pks-commands.html
is a spam trap. DON'T USE IT! |
Use: js******@LinxNet.com | http://jimsun.LinxNet.com
Jul 17 '05 #7
simply put, use PHPMailer. ever since replacing all of PHPs crappy mail()
with PHPMailer, i have never had a single problem.

"Jim Seymour" <js******@LinxNet.com> wrote in message
news:10*************@corp.supernews.com...
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
newline-terminated.

The mail() function takes up to five parameters:

mail(recipient, subject, message, [headers [,parameters]])

The ones of interest here are the first four. The questions are
these:

1. Since recipient and subject are not multi-line, and, from the
web form, don't even contain newlines, is it safe to assume
they need neither newlines nor carriage-returns?

2. The message, from the web form, contains newlines. I assume
all newlines need carriage-returns inserted in front of them?

3. The headers are created, in the web form processing, by
appending newline-terminated strings to a variable (e.g.:
headers .= "blah: yadda\n";). I presume that this string
likewise needs carriage-returns inserted before the newlines?

4. I've seen mention of problems with "hanging carriage-returns."
I presume that simply means there should be no line, blank or
otherwise, that contains a carriage-return w/o an accompanying
newline?

Assuming all the above to be true, my four parameters would look like:

recipient: "so******@example.com"
subject: "Some subject"
message: "Some message\r\ntext\r\ngoes here\r\n"
headers: "Header1: foo\r\nHeader2: bar\r\nHeader3: baz\r\n"

Is the above what (some?) MS-Windows mail servers want to see?

TIA,
Jim
--
Jim Seymour | PGP Public Key available at:
|
http://www.uk.pgp.net/pgpnet/pks-commands.html
|
| http://jimsun.LinxNet.com

Jul 17 '05 #8

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

Similar topics

13
by: Jeager | last post by:
Why is it, Microsoft manage to write operating systems and office applications with every bell and whistle facility known to man. Yet, even after years and years of development they still cannot...
7
by: Dave | last post by:
We are trying to migrate a MS SQL server app to DB2 8.1 Linux platform. Our database has got about 300+tables with total size - 150 GB We are using MS SQL's BCP utility to extract data from...
4
by: sql guy123 | last post by:
HI, I'm pretty new to MS SQL, My problem is setting .... =Format$(Date(),"mm" & "/1/" & "YYYY") (Which is from my MS ACCESS database)
2
by: Ted | last post by:
1) In several tables, in my MySQL version, I created columns using something like the following: `ab_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, This...
0
by: aakash | last post by:
Hello Guys I am upsizing ms access project to give it a ms sql connectivity I am having problem in accessing form control values in ms sql function CREATE FUNCTION "ReportList DateRange"() ...
0
by: aakash | last post by:
Hello Guys I am upsizing ms access project to give it a ms sql connectivity I am having problem in accessing form control values in ms sql function CREATE FUNCTION "ReportList DateRange"() ...
13
by: Lambda | last post by:
In an interview, I was asked: Define a function to split a string with some token. I said let the function return a string array. He asked me how do i know the array size. Yes, I have to...
0
by: VaBa | last post by:
Hi, Need some help.. I have a VBA class module in MS ACCESS. In the same MS ACCESS app, I am calling a .NET DLL (which i have exposed as COM-visible) and passing BYREF an instance of the VBA class...
3
by: keirnus | last post by:
Hello once again... I made a function in Excel. The function does some error checking within the Excel file. To be easy for me, I want my code in MS Access to simply call the function in Excel....
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.