|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-03-28 21:41 UTC] me at mattbeale dot plus dot com
System Spec:
Pentium 2 350Mhz, 256MB RAM, Windows 2000 Professional SP3, Apache 1.3.27 Win32 PHP/4.3.2.2 RC (20030328 Win32 stable from snaps.php.net - Build Date: Mar 28 2003 18:11:34) using Apache ISAPI module with GD2 support enabled in php.ini.
The Problem:
The mail() function in PHP hangs when talking to my ISP mail server, causing the Apache child process to hang indefinitely and ultimately requiring it to be closed forcefully by stopping and restarting the system service. There are never any errors reported by PHP, not even those of the maximum execution timeout variety, so this would indicate to me that something is very wrong somewhere. I can reproduce this 100% and it happens regardless of how the mail function is written, even a simple <?php mail('myemail@isp.com', 'Hello', 'Hello There'); ?> will cause it to hang.
To try and rectify this problem myself, I have formatted and reinstall Windows 2000, completely uninstalled and reinstalled both Apache and PHP several times, tried various recent versions of PHP and tried using only a very basic httpd.conf/php.ini, with only required settings for the SMTP support under Windows and it still does it.
Using a packet-sniffer, I am able to monitor PHP as it is talking to my ISP's mail server. Unless I'm reading things incorrectly, PHP never gets past the initial HELO <machine name> command, even though my ISPs mail server does respond with 250 OK, indicating that it was successful. PHP blatantly ignores this and instead chooses to sit there like a lemon, as if nothing ever happened.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 12:00:01 2025 UTC |
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 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 */