0

Here is my php and HTML code for one of my forms, There are 4 forms on the website and the php code is basically the same on all for obviously the HTML code is different because they are asking for different information and different form names, but are very similar. I have looked at a previous question that was basically the same question, however their code was much different and they just had an extra mailto tag, this is not the case in this instance. If I move the mail tag up it doesn't send me a blank email when they view the page but sends me an email for every entry on the form. I don't know php really at all and I do not quite understand the foreach ($_POST as $key => $value) line.

   <?php
   $mailto = "ppmrent@yahoo.com";
   $subject = "Feedback Form";
   $message = $_POST['message'];
   $header  = "From: ".$_POST['email'];
   foreach ($_POST as $key => $value)
   {
      if (!is_array($value))
      {
        $message .= "\n".$key." : ".$value;
      }
   }
   mail($mailto, $subject, $message, $header);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Feedback</title>
<meta name="generator" content="Quick 'n Easy Web Builder - http://www.quickandeasywebbuilder.com">
<style type="text/css">
body
    {
   background-color: #FFFFFF;
   color: #000000;
   font-family: Arial;
   font-size: 13px;
   line-height: 1.1875;
   margin: 0;
   padding: 0;
}
a
{
   color: #0000FF;
   text-decoration: underline;
}
a:visited
{
   color: #800080;
}
a:active
{
   color: #FF0000;
}
a:hover
{
   color: #0000FF;
   text-decoration: underline;
}
#wb_Text2
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
}
#Image2
{
   border: 0px #000000 solid;
   left: 0;
   top: 0;
   width: 100%;
   height: 100%;
}
#Image1
{
   border: 0px #000000 solid;
   left: 0;
   top: 0;
   width: 100%;
   height: 100%;
}
#wb_Text3
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
 }
#TextMenu1
{
   color: #000000;
   font-family: Arial;
   font-weight: bold;
   font-size: 19px;
   font-style: normal;
   margin: 0;
   padding: 0;
}
#TextMenu1 a
{
   color: #FFFFFF;
   text-decoration: underline;
}
#TextMenu1 a:hover
{
color: #58585B;
text-decoration: underline;
}
#TextMenu1 span
{
   margin: 0px 5px 0px 0px;
}
#Image3
{
   border: 0px #000000 solid;
   left: 0;
   top: 0;
   width: 100%;
   height: 100%;
}
#wb_Text1
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
}
#wb_Form1
{
   background-image: url(images/Feedback_Form1_bkgrnd.png);
   background-repeat: repeat-x;
   background-position: left top;
   border: 0px #000000 solid;
}
#wb_Text4
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
}
#Editbox1
{
   border: 1px #C0C0C0 solid;
   background-color: #FFFFFF;
   color :#000000;
   font-family: Arial;
   font-weight: normal;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#wb_Text9
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
}
#TextArea1
{
   border: 1px #C0C0C0 solid;
   background-color: #FFFFFF;
   color :#000000;
   font-family: Arial;
   font-weight: normal;
   font-size: 13px;
   text-align: left   resize: none;
;
}
#Button1
{
   border: 1px #A6A6A6 solid;
   background-color: #F0F0F0;
   color: #000000;
   font-family: Arial;
   font-weight: bold;
   font-size: 13px;
}
#wb_Text10
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
}
#wb_Text11
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
}
#Editbox6
{
   border: 1px #C0C0C0 solid;
   background-color: #FFFFFF;
   color :#000000;
   font-family: Arial;
   font-weight: normal;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#wb_Text12
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
}
#Editbox7
{
   border: 1px #C0C0C0 solid;
   background-color: #FFFFFF;
   color :#000000;
   font-family: Arial;
   font-weight: normal;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#wb_Text13
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
 }
#Editbox8
{
   border: 1px #C0C0C0 solid;
   background-color: #FFFFFF;
   color :#000000;
   font-family: Arial;
   font-weight: normal;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
 }
 #wb_Text14
{
   background-color: transparent;
   border: 0px #C0C0C0 solid;
   overflow-y: hidden;
   padding: 0;
   text-align: left;
 }
 #Editbox9
 {
    border: 1px #C0C0C0 solid;
    background-color: #FFFFFF;
    color :#000000;
    font-family: Arial;
    font-weight: normal;
    font-size: 13px;
    text-align: left;
    vertical-align: middle;
 }
 #wb_Text6
 {
    background-color: transparent;
    border: 0px #C0C0C0 solid;
    overflow-y: hidden;
    padding: 0;
    text-align: left;
 }
 </style>
 <script type="text/javascript">
 <!--
 function ValidateFeedback(theForm)
 {
    if (theForm.Editbox1.value == "")
    {
       alert("Please enter a value for the \"Name\" field.");
       theForm.Editbox1.focus();
       return false;
    }
    if (theForm.Editbox8.value == "")
    {
       alert("Please enter a value for the \"Email\" field.");
       theForm.Editbox8.focus();
       return false;
    }
    if (theForm.Editbox9.value == "")
    {
       alert("Please enter a value for the \"Phone\" field.");
       theForm.Editbox9.focus();
       return false;
    }
    if (theForm.Editbox7.value == "")
    {
       alert("Please enter a value for the \"Address\" field.");
       theForm.Editbox7.focus();
       return false;
    }
    if (theForm.TextArea1.value == "")
    {
       alert("Please enter a value for the \"Description\" field.");
       theForm.TextArea1.focus();
       return false;
    }
    return true;
 }
 //-->
 </script>
 </head>
 <body>
 <div id="wb_Text2"      style="position:absolute;left:189px;top:52px;width:671px;height:112px;z- index:15;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"> <strong>Professional Property Managment</strong></span></div>
 <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"> <strong>401 E Springfield Ave.,</strong></span></div>
 <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"> <strong>Champaign, IL 61820</strong></span></div>
 </div>
 </div>
 <div id="wb_Image2"  style="position:absolute;left:1px;top:2px;width:1051px;height:221px;text- align:left;z-index:16;">
 <img src="images/RadialBKGRND.jpg" id="Image2" alt=""></div>
 <div id="wb_Image1"  style="position:absolute;left:35px;top:44px;width:132px;height:113px;text-align:left;z-index:17;">
 <img src="images/ppm logo.jpg" id="Image1" alt=""></div>
 <div id="wb_Text3" style="position:absolute;left:190px;top:52px;width:671px;height:112px;z-index:18;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"> <strong>Professional Property Managment</strong></span></div>
 <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>401 E Springfield Ave.,</strong></span></div>
 <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>Champaign, IL 61820</strong></span></div>
 </div>
 </div>
 <div id="TextMenu1" style="position:absolute;left:860px;top:187px;width:187px;height:30px;z-index:19">
 <span>[<a href="./index.html" title="Home">Home</a>]</span><span>[<a  href="./ContactUs.html" title="Contact Us">Contact Us</a>]</span></div>
 <div id="wb_Image3" style="position:absolute;left:1px;top:281px;width:1051px;height:15px;text-align:left;z-index:20;">
 <img src="images/RadialBKGRND.jpg" id="Image3" alt=""></div>
 <div id="wb_Text1" style="position:absolute;left:5px;top:232px;width:1043px;height:56px;z-index:21;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div style="text-align:center"><span style="font-family:'Arial Black';font-size:32px;color:#400000;">Feedback</span></div>
 </div>
 </div>
 <div id="wb_Form1" style="position:absolute;left:4px;top:312px;width:1051px;height:374px;z-index:22;">
 <form name="Feedback" method="post" action="Feedback.php" id="Form1" onsubmit="return ValidateFeedback(this)">
 <div id="wb_Text4" style="position:absolute;left:92px;top:20px;width:885px;height:39px;z-index:0;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div style="text-align:center"><span style="font-size:24px;color:#400000;"><strong>We Welcome Your Feedback</strong></span></div>
 </div>
 </div>
 <input type="text" id="Editbox1" style="position:absolute;left:113px;top:68px;width:367px;height:23px;line-height:23px;z-index:1;" name="Name" value="" tabindex="1">
 <input type="submit" id="Button1" name="" value="Send" style="position:absolute;left:886px;top:326px;width:96px;height:25px;z-index:2;" tabindex="8">
 <div id="wb_Text10" style="position:absolute;left:58px;top:73px;width:56px;height:22px;z-index:3;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div>* Name:</div>
 </div>
 </div>
 <div id="wb_Text11" style="position:absolute;left:762px;top:104px;width:52px;height:20px;z-index:4;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div>Work #:</div>
 </div>
 </div>
 <input type="text" id="Editbox6" style="position:absolute;left:815px;top:99px;width:170px;height:23px;line-height:23px;z-index:5;" name="Work Phone" value="" tabindex="5">
 <input type="text" id="Editbox8" style="position:absolute;left:118px;top:102px;width:265px;height:23px;line-height:23px;z-index:6;" name="Email" value="" tabindex="3">
 <div id="wb_Text14" style="position:absolute;left:422px;top:338px;width:167px;height:18px;z-index:7;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div>* Denotes Required Field</div>
 </div>
 </div>
 <input type="text" id="Editbox9" style="position:absolute;left:555px;top:99px;width:193px;height:23px;line-height:23px;z-index:8;" name="Phone" value="" tabindex="4">
 <div id="wb_Text13" style="position:absolute;left:58px;top:105px;width:54px;height:22px;z-index:9;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div>* Email:</div>
 </div>
 </div>
 <input type="text" id="Editbox7" style="position:absolute;left:570px;top:65px;width:302px;height:23px;line-height:23px;z-index:10;" name="Address" value="" tabindex="2">
 <div id="wb_Text12" style="position:absolute;left:502px;top:68px;width:63px;height:20px;z-index:11;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div>* Address:</div>
 </div>
 </div>
 <div id="wb_Text6" style="position:absolute;left:411px;top:104px;width:140px;height:21px;z-index:12;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div>* Home or Cell Phone #:</div>
 </div>
 </div>
 <div id="wb_Text9" style="position:absolute;left:59px;top:143px;width:116px;height:25px;z-index:13;">
 <div style="font-family:Arial;font-size:13px;color:#000000;">
 <div><span style="font-size:16px;"><strong>* Comments:</strong></span></div>
 </div>
 </div>
 <textarea name="Description" id="TextArea1" style="position:absolute;left:56px;top:169px;width:923px;height:143px;z-index:14;" rows="1" cols="1" tabindex="6"></textarea>
 </form>
 </div>
 </body>
 </html>
Brandy
  • 1
  • 2
  • Not suprising really. Look at your code, bench test it. Specifically, what happens when you launch the page for the first time – RiggsFolly Jan 25 '16 at 16:59
  • I have launched the page, and it works fine except that it sends a blank email when a user views the page and then submits the responses when they click submit – Brandy Jan 25 '16 at 17:20
  • Look at your script: it opens, sets variables, then sends an email using the `mail` function. This happens if some one has filled out the form, or is just opening the page for the first time. – Martin Bean Jan 25 '16 at 17:28
  • Ok, I can see it has variables but I don't know how to write the code to only send it once it has been submitted, because the foreach code I get tells it to get a value for each entry, and I need it to send me the email with the entries but how do I tell it to only mail if that happens. I'm sure it is probably a small piece of code that I am missing but I don't know how to write it. – Brandy Jan 25 '16 at 17:42

0 Answers0