Passing global variable to function mail()

Hi,

I am breaking my head with this mail() function.

I have a config.inc.php file and in there I have a global variable with i set as:
global $email;

In another php page, I am sending a form using the mail() function.

Here is the example:
// Target email address.
$to = $email;

// Your subject.
$subject = “Registration Confirmation”;

// Sender. You may put the sender’s email address after “from:”. This example file use "[email protected]"
$mail_from=“from: “.$_POST[‘email’].” n”;
#$mail_from=“from: test@localhost n”;

// Set this email to HTML email format.
$mail_from .=“Content-Type: text/html; charset=utf-8 n”;

// Your message.
$message = “Thank you for registering at the User Registration site.

”;
$message .= “To activate your account, please click on this link.”;
$message .= “

”;

mail($to,$subject,$message,$mail_from);

It seems that the “$to” which retrieves the global variable $email doesn’t work.
If i do “echo $email;”, i do see the proper variable, but for some reason, passing it onto to the mail() function gives me the error…
"mail() [function.mail]: SMTP server response: 551 User not local. We don’t relay "

Can anyone help?

Thanks

Well, first thing is first…

What is a global variable?

A global variable is something defined across the boards…

global $email;
means the same thing as

$_SESSION[‘email’];
$_GET[‘email’];
$_POST[‘email’];
$email;

and so on…

You are declaring the variable 2 times, once in the config file, once when the user posts it…

A better way is simply make a configuration array like $config[‘email’] and require the config file in your email file and simply call that :-)

$email;
im declaring in my inc. file so that I can use it throughout the site.

$_POST[‘email’];
Is the email the user entered in the form in the registration page.

I went step by step with the sending form to email and noticed that the only place that is giving me errors is the $to = $email variable. If I just write the actual email: $to = “me@localhost”, then it works just fine.

any ideas?

you may have global variables enabled on your server - where it will use overwrite the $email variable with what the user inputs - which can be extremely dangerous because the end user can rewrite any variable you declare, including mysql queries and so on…

disable globals

I am not sure what you mean by this, do you mean to disable something in my phpinfo?
If yes, can you tell me which variables in phpinfo must be disabled?

thanks again

register_globals needs to look like this

register_globals = Off

I tried to do what you said and even restarted the apache server, but still doesn’t seem to want to work.

I still get this error when I am calling my global variable from my inc.php file that is included in my other php file:

mail() [function.mail]: SMTP server response: 551 User not local. We don’t relay

Sounds like a server config issue. What mailserver software are you using?

Argosoft Mail Server (not the Pro)
Using is on localhost, to send to local host.

Google gives me this.
And perhaps contacting Argosoft Support is an option? It looks like a general warning message, so they probably implemented it in the code.

Sponsor our Newsletter | Privacy Policy | Terms of Service