PHP form sends blank email when a user views the form and another when submitted

My site has 4 forms all with the same “basic” php code meaning I’ve changed the coding so that it corresponds to the specific form. When someone views the form it sends a blank email, then when the fill out and submit the form it sends an email with the values. I know that in the code there are variables defined and then it says to email, what I can’t figure out is how to write the code that I know is missing that tells it to ONLY send the email if the form is filled out and submitted not just viewed. If I move the code that tells it to email up, it emails after every entry is filled in, so for example if it has three entries I would get an email for the first entry, the second entry gives me the the first and second entries, the third gives me the first, second, and third entries. So all I really need is the last one.

Here is my php and HTML code for one of my forms, I don’t know php really at all although I understand the “foreach ($_POST as $key => $value)” code is getting the value for each entry, which is why if I move the mail code up then I get an email “foreach” entry. I know there is code missing but I cannot figure out how to write it.

<?php $mailto = "[email protected]"; $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); ?>

First, please place your code inside of the PHP tags. It helps us a lot!

Normally, you handle pages like this… You have a form which has a “submit” button. The first thing you check is
that button. If it is not pressed, you do nothing. My guess is that is what you are asking. So, as a sample, not
real code, let’s say you have:

This sample has just one input field and a submit button. In your code, you would handle it loosely like this: <?PHP if (isset($_POST["send_data"])) { // user submitted data... $some_variable = $_POST["input_data"]; // Here you would validate the data to make it secure and usable and maybe set up error messages if not ... do something with data, such as send an email... } ?> As you see, the above code does nothing until the user presses the send button. (Submit button) Normally, this code would be on the same page as the form and once all of the data is processed, the form's code would redirect to the next page needed or just back to itself depending on what you need done next. Not sure if that is what you are asking, but, let us know...

With the web creator program, I cannot add code into the form. It allows me to enter code before, after, and into a tag (but it gives me a limited choice of tags that I can put it in and I can’t adjust it more, i.e. it offers for me to put it in the tag so it inserts the code like this “<body >”. I cannot move it to anywhere else in the code, and this is of course not where I need to code. So I cannot add this code into the form, the other code you suggested for the form is already present in the current code. The code that I can change and add to is the php code. So I can add the “if (isset($_POST[“send_data”]))” code but of course it won’t work without the HTML code in the form. I am not new to HTML code but this is the first I have ever dealt with php coding. I assume that with the php coding that I have, that the variables are set and then it says to mail, but I don’t know what code needs to be in the php code to tell it to ONLY mail if the submit button is pressed, or where in the php code I would need to place the line of code.

Sorry, BPPM, I was tired and misread your question…

What you are looking for is “validation” of the inputs to make sure they are is inputs and that they are valid.
To check for blank inputs is easy… Loosely something like this:
[php]

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

[/php]
This basically looks at the posted “input_data” field and trims out spaces from the beginning and end, then sees
if it is empty or not. You can use the empty() function for this, too, but, you still need to trim the values first.

You should think about using a check to make sure the data does not contain programming or other bad codes.
This is done thru validation. The version of PHP that you are using makes a difference on how that is done.
Let us know which version and we can help you with that code, also… Hope this helps!

I am using php version PHP5. When I insert that line of code, it doesn’t send me the blank email but it also doesn’t send me the submitted form either. Maybe it would help if I posted all the code for this form.

[php] <?PHP
$mailto = "[email protected]";
$subject = “Feedback Form”;
$message = $_POST[‘message’];
$header = “From: “.$_POST[‘email’];
foreach ($_POST as $key => $value)
{
if (!is_array($value))
{
$message .= “\n”.$key.” : “.$value;
}
}
if (trim($_POST[“input_data”])!=””) mail($mailto, $subject, $message, $header);
?>
[/php]

    <!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>Company</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>Address</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>City,State, Zip</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>Company</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>Address</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>City, State, Zip</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>

Well, next time, please put your code inside the PHP tags. It makes it so very much easier for us…

Perhaps I am not understanding what you want… Normally, this is how I would send that email out:
[php]

<?PHP $mailto = "[email protected]"; $subject = "Feedback Form"; $message = "\nMessage sent from: " . $_POST["Editbox1"]; $message .= "\nAddress: " . $_POST["Editbox7"]; $message .= "\nEmail: " . $_POST["Editbox8"]; $message .= "\nPhone: " . $_POST["Editbox9"]; $message .= "\nWork Phone:: " . $_POST["Editbox6"]; $message .= "\nMessage content: " . $_POST['TextArea1']; $header = "From: ".$_POST['Editbox8']; mail($mailto, $subject, $message, $header); ?>

[/php]
This is using the code you posted combined with the HTML of the form. Note that when I built the message
that is sent in the email that the first line uses “=” and the rest use “.=” to append the rest of the info…

Hopefully that is what you are looking for. Normally, I would have created this as a HTML email as most all
mail readers now use HTML. I normally make the email look just like the website. It adds a lot of “fancy” to
the emails… Let us know if that is what you needed…

[php]

<?PHP $mailto = "[email protected]"; $subject = "Feedback Form"; $message = $_POST['message']; $header = "From: ".$_POST['email']; foreach ($_POST as $key => $value) { if (!is_array($value)) { $message .= "\n".$key." : ".$value; } } if (trim($_POST["input_data"])!="") 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>Company</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>Address</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>City,State, Zip</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>Company</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>Address</strong></span></div>
      <div style="text-align:center"><span style="font-size:32px;color:#FFFFFF;"><strong>City, State, Zip</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>

[/php]

I tried the latest code and it did send me an email but it sent a blank email as soon as I clicked on the form, before I had entered any information into any of the fields.

Maybe I am not explaining this well, on my website I have the code above, when I publish this page, the form I am not getting an email at all, however if I add the
"$message = "\nMessage sent from: " . $_POST[“Editbox1”];
$message .= "\nAddress: " . $_POST[“Editbox7”];
$message .= "\nEmail: " . $_POST[“Editbox8”];
$message .= "\nPhone: " . $_POST[“Editbox9”];
$message .= "\nWork Phone:: " . $_POST[“Editbox6”];
$message .= "\nMessage content: " . $_POST[‘TextArea1’];
$header = "From: “.$_POST[‘Editbox8’];
mail($mailto, $subject, $message, $header);”
Code, I get a blank email as soon as someone visits the page without them ever having entered any info or clicking submit, then I will get a second email once they have entered and submitted the info. I am trying to figure out how to get the code to send me the form once it has been submitted but ONLY after the user clicks submit.

Best way is to tell it to only process the mailing logic if you have actually posted the form.

[php]<?PHP
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
$mailto = "[email protected]";
$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);
}
?>[/php]

Yep, I mentioned that in my first post… Thanks for explaining it in more detail to the OP…
(Have been short on time lately…)

The form is actually posted, published, and working, the problem is that it sends a blank email when the user views the page and another when they actually submit the form.

Well, BPPM, if the process is working now and all that you are not getting is the content, then it is the way that
you are building the content that is sent out. My guess is that it is your code that checks for it to be an array.
There is no reason to check for an array as you already have pulled it out of the array. Most likely that is the
issue… So, change this:
[php]
foreach ($_POST as $key => $value)
{
if (!is_array($value))
{
$message .= “\n”.$key." : “.$value;
}
}
[/php]
To just this version:
[php]
$message = “”;
foreach ($_POST as $key => $value)
{
$message .= “\n”.$key.” : ".$value;
}
[/php]
Note that I set the message to blank first. You need to do that so that it will not add to the last message that
the user sent out. (In case they send two in a row)
Now, I would not do it this way for my projects. I would still format it so the email is clearer on what is being
sent for data like this:
[php]
$message = "\nMessage sent from: " . $_POST[“Editbox1”];
$message .= "\nAddress: " . $_POST[“Editbox7”];
$message .= "\nEmail: " . $_POST[“Editbox8”];
$message .= "\nPhone: " . $_POST[“Editbox9”];
$message .= "\nWork Phone:: " . $_POST[“Editbox6”];
$message .= "\nMessage content: " . $_POST[‘TextArea1’];
[/php]
Let us know if any of this fixes it for you…

Of the four forms on my site, I chose the feedback form to submit here because it was the most simple, however there is also an application form on the site with approximately 80 fields to fill out so if I did it this way :

                 $message = "\nMessage sent from: " . $_POST["Editbox1"];
                 $message .= "\nAddress: " . $_POST["Editbox7"];
                 $message .= "\nEmail: " . $_POST["Editbox8"];
                 $message .= "\nPhone: " . $_POST["Editbox9"];
                 $message .= "\nWork Phone:: " . $_POST["Editbox6"];
                 $message .= "\nMessage content: " . $_POST['TextArea1'];

It is going to pretty long, I can if that will make it work, the issue isn’t getting it to send me the content, it is getting it to ONLY send me the content. Right now if you went to my site, and clicked on the feedback form page, it will automatically send me a blank email, without the user ever having entered anything or maybe they just clicked on the link to the page and didn’t want to send anything, I still get a blank email. If they want to submit feedback I get the blank email from when they clicked to the page, and another email with all the content when then fill out and submit the form. i.e.

I get this email when someone clicks on the page before any content is filled out or submitted:

To: [email protected]

"

and I also get this email once the user has submitted the content:

"
To:[email protected]
Name : testing
Work_Phone : testing
Email : testing
Phone : testing
Address : testing
Description : testing
"
So it isn’t that the form isn’t working I just want to get rid of the blank initial email from someone viewing the page, I only want the submitted form that the user submits

Well, back to my first post and the one from JimL, you need to check if the send button is pressed.
If you do not do that, the email will post as soon as you go to the page or if you refresh the page.

In my first post, I showed you how to check when the “send” or “submit” button is pressed. Then, JimL showed
you how to check when the page was posted no matter which button was pressed. Either way should work for
your project. If you have your forms set up as separate ones on the page, you can use different submit buttons
and have each section handle the user’s inputs for just the correct section.

If you have a comment section set up, I would place a “send-comment” button in that section and have code to
just pull that info, not the entire page’s data. Why grab the other 80 fields if you are only sending five…?

For a section with 80 fields to enter, that might be easier to just use an array for those. You can set up the
inputs for sections that are repeated using an input array. Not sure if that makes sense to you or not.

So, first, I would add in either the if (isset($_POST[“send_data”])) { with the button you use in place of the
“send_data” part, or the if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) { which checks if the page was
posted. Either of these checks will remove the problem of the form sending blank emails when you go to the
page or refresh it.

Next, I would think out how your page sends data from the multiple forms. You can create as many different
forms on your page as you need. Loosely like this:

some fields... some fields... etc... If you create your page with multiple forms, you can have separate areas in your PHP code that checks just for one form and handles the special data needed for that area only. Loosely like: if (isset($_POST["send_comment"])) { // Handle user's comments, send email... etc... } if (isset($_POST["enter_new_user"])) { // receive the 80 fields for the new user's data... etc... } Handling each as a separate forms, you can customize how you use the data sent to your code.

I am so sorry I missed the part of the code that JimL posted, for whatever reason when I looked at it I thought it was the same code I already had, I just glossed right over it and I missed that line of code… When I add that… SUCCESS!!! Thank you guys so much, You’re the best!!!

Thanks again
BPPM

Congrats! Glad you solved it… Give JimL some Karma for the help! See you if you have another problem!

Sponsor our Newsletter | Privacy Policy | Terms of Service