I am not a php person and need some help, please.
I have the following rudementary form to email code.
(I did not write this code.)
It is in a file named mail.php on the server.
PHP Code:
<?PHP
$to = "me@this.com";
$subject = "Results from your Request Info form";
$headers = "From: My Site";
// redirect? 1=yes 0=no
$forward = 0;
$location = "mysite.com";
$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.";
}
?>
The following is a typical response:
Below is the result of your feedback form.
It was submitted on Friday, February 1st, 2013 at 03:30 PM.
name : test
Phone : asdf
Email :
sdfg@sdfg.com
Submit : Submit Request
THe code works fine when called from the web page with the form except every now and then I get an email without the fields such as this:
Below is the result of your feedback form.
It was submitted on Friday, February 1st, 2013 at 05:30 PM.
I discovered that if you access the mail.php file directly by typing
http://mysite.com/mail.php
in your browser you get an email without the fields.
Is there a better way of doing this?
Any comments would be helpful. Thanks.