Forum Moderators: coopster

Message Too Old, No Replies

register_globals and $_POST problem

         

82gt

1:53 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



An administrator of a hosting company using a Windows based server is telling me that my PHP code is deprecated and won't work with PHP 5 with register_globals turned off. I have used this code successfully with numerous servers running PHP 4.3 with register_globals turned off. Here is the code:

<?
$to = "yourname@yourdomain.com";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From: $email\n";
mail($to, $name, $message, $headers);
print("Mail sent to $to");
?>

The code takes information from a form using $_POST and sends to an email address using mail(). When someone submits the form the following error message is displayed:

PHP Warning: mail() [function.mail]: SMTP server response: 551 relaying denied in F:\root\company\www\filename.php on line 15

The administrator says my code is not compatible with PHP 5 with register_globals turned off and is causing the problem. I think the code should work as it has on servers running PHP 4.3. If someone could give a second opinion or inform me if this code is incompatible with PHP 5 with register_globals turned off, I would greatly appreciate it. Thanks.

ChadSEO

2:59 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



82gt,

Welcome to WebmasterWorld!

I've worked for a web hosting company, so I'm very familiar with how the system administrators think - I was one. Whenever there is an issue, first blame it on the user. If they can't fix it after a few weeks, I might deign to actually look at the problem. I suspect that is what is happening here.

With that error message: "SMTP server response: 551 relaying denied", I'm fairly certain the issue is with whatever mail server it is attempting to use. Outgoing mail servers, or SMTP servers, are configured to allow 2 types of mail: 1) messages intended for that server, usually based on domain name, and 2) messages from certain IP addresses that are allowed to send mail through it. That's why I can use AOL's mail server to send email to anyone @aol.com, but not to @msn.com, or I can use my ISP's mail server and send to anyone. All other mail is blocked with "relaying denied".

There are a couple different places where the problem could lay - either in the mail server setup, or in the PHP configuration. You're best bet to get someone to fix this (and verify it's not your problem) would be create a very basic php file that tries to send to a specific email address using all hard coded strings - nothing from $_POST. Make sure you use the same email address that you were trying when you submited the form.

Hope this helps!

Chad

ChadSEO

3:28 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



To follow up,

I'm no expert, but as I read the documenation, $_POST is the correct way to access variables with register_globals off, see the documentation here: [us2.php.net ]

In PHP 4.2.0 and later, the default value for the PHP directive register_globals is off. This is a major change in PHP. Having register_globals off affects the set of predefined variables available in the global scope. For example, to get DOCUMENT_ROOT you'll use $_SERVER['DOCUMENT_ROOT'] instead of $DOCUMENT_ROOT, or $_GET['id'] from the URL http://www.example.com/test.php?id=3 instead of $id, or $_ENV['HOME'] instead of $HOME.

Chad

82gt

3:44 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



Thanks Chad, that was a big help. I'll perform that test without using $_POST with the email address hard coded in a string. I uploaded info.php files to this server where I was having problems and to other servers where my PHP code worked well. I noticed that in the SMTP settings on the server where I was having problems, the SMTP settings were set at hostingdomainname.com. By comparison, the servers where I had no problems the SMTP settings were set at localhost. Can you tell me, is this significant? Thanks again for your help, Chad.

ChadSEO

4:06 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



82gt,

On the server where the SMTP server is localhost, the server must be set up to send mail as well. On the other server, where the SMTP server is hostingdomainname.com, it's a good chance that hostingdomainname.com is not a valid mail server. It could also be that an SMTP server is installed, but not configured to actually be used. In any event, the SMTP server is specified in the php.ini configuration file, and I don't think there's a way for you to override that.

Chad

82gt

4:26 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



Chad,

Thanks a lot for your input. Your opinion has been a big help and I'm confident I'll be able to resolve this issue between ISP Adminsistrator, myself and the customer.

82gt

ChadSEO

4:40 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



82gt,

Glad I could help, good luck, and let me know if any other questions come up.

Chad