title: variable exists but giving an undefined variable error
body: <p>This is really getting to me.....I keep getting an undefined variable even if it's there!
  How do I get rid of this error? Not to mention I'm not even sure the form works because of using xampp and not on a live server</p>
  
  <p>Form on contact.php</p>
  
  <pre><code>        &lt;div class="col-md-6 col-md-offset-3 emailForm"&gt;
                      &lt;?php if (isset($result)) { echo "$result";} ?&gt;
              &lt;form method="post" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for="name"&gt;Your Name:&lt;/label&gt;
                      &lt;input type="text" name="name" class="form-control" value="&lt;?php echo isset($_POST['name']) ? $_POST['name'] : ''; ?&gt;" /&gt;
  
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for="subject"&gt;Subject:&lt;/label&gt;
                      &lt;input type="text" name="subject" class="form-control" value="&lt;?php echo isset($_POST['name']) ? $_POST['subject'] : ''; ?&gt;" /&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for="email"&gt;Your Email Address:&lt;/label&gt;
                      &lt;input type="email" name="email" class="form-control" value="&lt;?php echo isset($_POST['name']) ? $_POST['email'] : ''; ?&gt;" /&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for="message"&gt;Your Message:&lt;/label&gt;
                      &lt;textarea class="form-control" rows="5" name="message"&gt;&lt;?php echo isset($_POST['name']) ? $_POST['message'] : ''; ?&gt;&lt;/textarea&gt;
                  &lt;/div&gt;
                  &lt;div class="text-center"&gt;
                      &lt;input type="submit" name="submit" class="btn btn-success btn-lg" value="Submit"/&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
      &lt;!-- Contact Form Ends --&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>sendemail.php code</p>
  
  <pre><code>&lt;?php
  
       if(isset($_POST["submit"])) {              
           if (!$_POST['name']) { 
               $error="&lt;br /&gt;Please enter your name"; 
           }       
           if (!$_POST['subject']) { 
               $error.="&lt;br /&gt;Please enter a subject"; 
           }          
           if (!$_POST['email']) { 
               $error.="&lt;br /&gt;Please enter your email address"; 
           }          
           if (!$_POST['message']) { 
               $error.="&lt;br /&gt;Please enter a message"; 
           }                   
           if ($_POST['email']!="" AND !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) {          
              $error.="&lt;br /&gt;Please enter a valid email address"; 
           }          
           if ($error) { 
               $result='&lt;div class="alert alert-danger"&gt;&lt;strong&gt;There were error(s) in your form:&lt;/strong&gt;'.$error.'&lt;/div&gt;';           
           } else { 
              if (mail("support@kf.com", "New Online Message!", "Name: ". $_POST['name']." 
                  Name: ".$_POST['name']."             
                  Subject: ".$_POST['subject'])) { 
           $result='&lt;div class="alert alert-success text-center"&gt;&lt;strong&gt;Thank you!&lt;/strong&gt; Please allow 24 to 48 hours for our support team to get back to you. Thank you. &lt;/div&gt;';      
           } else {        
              $result='&lt;div class="alert alert-danger"&gt;Sorry, there was an error sending your message. Please try again later.&lt;/div&gt;';         
          }    
      }    
  }
  
  ?&gt;
  </code></pre>