#22947 [Com]: mail function hang-up
| From: | lwillis at plus dot net | Date: | Mon, 11 Aug 2003 10:16:11 +0000 |
| Subject: | #22947 [Com]: mail function hang-up | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-45714@lists.php.net to get a copy of this message | ||
ID: 22947
Comment by: lwillis at plus dot net
Reported By: me at mattbeale dot plus dot com
Status: Assigned
Bug Type: Mail related
Operating System: Windows 2000 SP4
PHP Version: 4CVS-2003-04-29 (stable)
Assigned To: edink
New Comment:
Probably easier to grab the patch from here:
http://www.lwillis.plus.com/php_sendmail_patch.patch
Lee
Previous Comments:
------------------------------------------------------------------------
[2003-08-11 05:15:01] lwillis at plus dot net
The patch below (I can't find anywhere to add this as an attachment -
shoot me if I'm being stupid) may fix the problem (Matt - could you try
it?). Not sure whether it will work correctly with multi-line
responses. This is untested - I don't have access to a win32 platform
to build on right now (Or a mail server that sends multi-line responses
to a HELO ...)
Index: win32/sendmail.c
===================================================================
RCS file: /repository/php-src/win32/sendmail.c,v
retrieving revision 1.55
diff -u -r1.55 sendmail.c
--- win32/sendmail.c 23 Jul 2003 16:03:10 -0000 1.55
+++ win32/sendmail.c 11 Aug 2003 10:10:54 -0000
@@ -882,11 +882,10 @@
/* Check for newline */
Index += rlen;
- if ((buf[Received - 4] == ' ' && buf[Received - 3] == '-') ||
+ if ((buf[3] == '-') ||
(buf[Received - 2] != '\r') || (buf[Received - 1] !=
'\n'))
/* err_msg fprintf(stderr,"Incomplete server
message. Awaiting CRLF\n"); */
- goto again; /* Incomplete
data. Line must be terminated by CRLF
- And not contain a space
followed by a '-' */
+ goto again; /* Incomplete
data OR multi-line response. Line must be terminated by CRLF */
if (buf[0] > '3') {
/* If we've a valid pointer, return the SMTP server
response so the error message contains more information */
------------------------------------------------------------------------
[2003-08-11 04:43:16] lwillis at plus dot net
As far as I can see from section 4.1.1.1 of RFC 2821 the response given
to the HELO command is perfectly valid.
http://www.faqs.org/rfcs/rfc2821.html
The check for a space and then dash was introduced into
win32/sendmail.c at version 1.20 with the following log entry:
--------------------------------------
revision 1.20
date: 2000/09/05 00:26:15; author: sterling; state: Exp; lines: +5
-2
This should fix the multiple-line problem.
--------------------------------------
Not sure which "multiple line problem" though - possibly bug 6537
Either way, the response we're sending looks like it should be handled
fine by PHP - and it certainly shouldn't cause a hang (I expect PHP is
waiting for more data trying to get the next line of a multi-line
response - but it should be doing this as the response code (250) is
followed by a space, not a dash ...
------------------------------------------------------------------------
[2003-08-03 09:05:38] me at mattbeale dot plus dot com
Does this not get acknowledgement unless the Status is set back to
Open?
------------------------------------------------------------------------
[2003-08-02 18:28:51] phpbugs at pligplob dot com
This does seem to be a fault in the Windows code, the Ack() function in
sendmail.c:
win32/sendmail.c(Ack):
...
if ((buf[Received - 4] == ' ' && buf[Received - 3] == '-') ||
...
It is specifically disallowing SPACE HYPHEN at the end of the SMTP
reply text that PlusNet's server is sending, but that seems to be
allowed by RFC2821.
However, since someone has deliberately blocked this pattern there must
be a reason for it, but it seems invalid to me.
When I modifed the php4ts.dll to use EHLO instead of HELO the SMTP
exchange completed successfully. PlusNet's server avoids the "illegal"
SPACE HYPHEN in its extended reply, so the hangup doesn't occur.
------------------------------------------------------------------------
[2003-07-30 15:39:46] me at mattbeale dot plus dot com
In addition to my previous message:
This PHP code works fine on both machines that have problems. I doubt I
need to tell you what it does?:
<?php
function bytesleft($fp) {
$status = socket_get_status($fp);
$bytes = $status['unread_bytes'];
return $bytes;
}
function sendtext($str) {
global $fp;
echo $str;
flush();
fwrite($fp, $str);
$ret = fread($fp, 1);
$ret.= fread($fp, bytesleft($fp));
return $ret;
}
$fp = false;
if ($fp = fsockopen('relay.plus.net', 25, $errno, $errstr, 1)) {
socket_set_timeout($fp, 1);
$hash = md5(uniqid(rand()));
echo sendtext("HELO server\r\n");
echo sendtext("MAIL FROM: me@mattbeale.plus.com\r\n");
echo sendtext("RCPT TO: me@mattbeale.plus.com\r\n");
echo sendtext("DATA\r\n");
echo sendtext("From: Matt Beale <me@mattbeale.plus.com>\r\n");
echo sendtext("Subject: [PHP] Test Subject - {$hash}\r\n");
echo sendtext("To: Matt Beale <me@mattbeale.plus.com>\r\n");
echo sendtext("\r\n");
echo sendtext("This is a test message sent from PHP\r\n");
echo sendtext("\r\n");
echo sendtext("Hash: {$hash}\r\n");
echo sendtext(".\r\n");
echo sendtext("QUIT\r\n");
fclose($fp);
}
?>
If Andrew happens to read this, I'd be interested to know if it works
for him. Plus I'd be very interested in what the PHP developers think
might be going on.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/22947
--
Edit this bug report at http://bugs.php.net/?id=22947&edit=1