form mailer help

I posted this before but I think something went wrong.
If this is a duplicate post. I am very sorry.

Please help with this php code. C and C# are really my languages.

It is intended to take the fields in a web form and place them in an email.

The other day, two emails were received only containing the line
“Below is the result of your feedback form. It was submitted on $date at $time.\n\n”
with no field information.

Might there be a flaw in this code?


<?PHP // Change "[email protected]" to your email. (you must keep the "" marks) $to = "[email protected]"; // This will be the subject of the Email when it is sent. $subject = "Results from your Request Info form"; // This will be who it is from, usually My site or something like that $headers = "From: My Site"; // redirect? 1=yes 0=no (this is the page you go to after you submit the form. // if left on 0 you will see a message then nothing will happen // if you select 1 you will see a message then go to the redirect page.) $forward = 0; // This will be the page you are redirected. // (if you keep it 0 you do not need one just delete ""; and leave ""; instead) $location = ""; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; if ($_SERVER['REQUEST_METHOD'] == "POST") { foreach ($_POST as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } else { foreach ($_GET as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } mail($to, $subject, $msg, $headers); if ($forward == 1) { header ("Location:$location"); } else { echo "Thank you for submitting our form. We will get back to you as soon as possible."; } ?>


I don’t see any problems with this code

Thanks for the reply m@tt.

Is it possible that the else part is sending a blank email?

[php]else { foreach ($_GET as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . “\n”; }[/php]

Actually, do you think the else part is needed at all?

That is not causing a problem but it is not necessary to switch between request methods.

If you expect either POST or GET you could use $_REQUEST instead.

Sponsor our Newsletter | Privacy Policy | Terms of Service