#3305 [Com]: Global vars and mail() unpredictability

From: Date: Sun, 16 Nov 2003 22:31:55 +0000
Subject: #3305 [Com]: Global vars and mail() unpredictability
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-50453@lists.php.net to get a copy of this message
ID: 3305 Comment by: o6y1 at hotmail dot com Reported By: joel at nextstudio dot com Status: Closed Bug Type: Other Operating System: Solaris 2.6 PHP Version: 4.0 Beta 3 New Comment: ÇÈí ãæÞÚ ÖÑÈ ÇáÇíãíá Previous Comments: ------------------------------------------------------------------------ [2000-01-24 17:47:28] torben at cvs dot php dot net This is a scoping problem, not a bug. Remember, global variables are not available by default inside functions. Add the following line: global $SERVER_NAME, $REQUEST_URI, $REMOTE_ADDR, $QUERY_STRING; as the first line of your function to allow access to those globals within status_mail(). Torben ------------------------------------------------------------------------ [2000-01-24 17:38:38] joel at nextstudio dot com $SERVER_NAME, $REQUEST_URI, and $QUERY_STRING aren't being echoed out in the email body. They work fine in the from and reply-to headers, though. Here's what i get in my email: -- begin email snippet -- Date: Mon, 24 Jan 2000 14:25:08 -0800 Message-Id: <200001242225.OAA04055@unionbay.> To: joel@nextstudio.com Subject: Success From: webmaster@unionbay.nexthost.com Reply-To: webmaster@unionbay.nexthost.com X-Mailer: PHP/4.0b3 Sender: nobody@unionbay.nexthost.com Zip search database rebuilt. Num of records: 8711 Monday, January 24, 2000 02:25:08 pm HOST: , URI: REMOTE_ADDR: -- end email snippet Below is the code that I used to generate the above response. -- begin script snippet1 -- /* * bool status_mail(bool end, string subj, string message, string recpt) * * email result status */ function status_mail($bomb, $subj, $msg, $recpt="joel@nextstudio.com") { $r = mail($recpt, $subj, $msg."\n\n".date("l, F j, Y h:i:s a")."\n". "HOST: ".$SERVER_NAME.", URI: ".$REQUEST_URI.$QUERY_STRING."\n". "REMOTE_ADDR: ".$REMOTE_ADDR."\n", "From: webmaster".$SERVER_NAME."\nReply-To: webmaster".$SERVER_NAME."\nX-Mailer: PHP/". phpversion()); if ($bomb) die($subj.": ".$msg); else echo $subj.": ".$msg; return $r; } -- end script snippet1 -- It's in it's own include file which is then called as: -- start script snippet2 -- status_mail(false, "Success", "Zip search database rebuilt.\n\nNum of records: ".$i); -- end script snippet2 -- $i is an int if that makes any difference. Any ideas? Joel ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=3305&edit=1

« previous php.bugs (#50453) next »