php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3305 Global vars and mail() unpredictability
Submitted: 2000-01-24 17:38 UTC Modified: 2000-01-24 17:47 UTC
From: joel at nextstudio dot com Assigned:
Status: Closed Package: Other
PHP Version: 4.0 Beta 3 OS: Solaris 2.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joel at nextstudio dot com
New email:
PHP Version: OS:

 

 [2000-01-24 17:38 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-01-24 17:47 UTC] 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
 [2003-11-16 17:31 UTC] o6y1 at hotmail dot com
??? ???? ??? ???????
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 03 03:01:29 2024 UTC