Why does this validation error occur before data is submitted in PHP form?
<p>I'm using a PHP form to forward data to an email address. Everything seems to work fine except the the error message ["You have not entered an email"] appears when the page is loaded, before any input from the user is entered, rather than through validation when submitted.</p>

<p>The form is here <a href="http://www.soulwatt.com/contact.php" rel="nofollow">http://www.soulwatt.com/contact.php</a></p>

<p>Note: I found this PHP code online after doing a search on how to forward data to email, so it is not mine. Please excuse the lack of proper code formatting.</p>

<pre><code>&lt;?php 
 $to = $_REQUEST['sendto'] ; 
 $from = $_REQUEST['Email'] ; 
 $name = $_REQUEST['Name'] ; 
 $headers = "From: $from"; 
 $subject = "soulwatt.com Contact Data!!"; 

 $fields = array(); 
 $fields{"Name"} = "Name"; 
 $fields{"Company"} = "Company"; 
 $fields{"Email"} = "Email"; 
 $fields{"Phone"} = "Phone"; 
 $fields{"list"} = "Mailing List"; 
 $fields{"Comments"} = "Comments"; 

 $body = "Soul Watt has received the following information:\n\n";

 foreach($fields as $a =&gt; $b)   {
    $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
    } 

 $headers2 = "From: noreply@soulwatt.com";
 $subject2 = "Thank you for contacting Soul Watt!"; 
 $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.soulwatt.com";

 if($from == '') {
      print "You have not entered an email. Please enter your email and try again.";
      } 
 else {

 if($name == '') {
      print "You have not entered a name.&lt;br /&gt;Please enter your name and try again.";
      } 

 else { 
 $send = mail($to, $subject, $body, $headers); 
 $send2 = mail($from, $subject2, $autoreply, $headers2);

 if($send)  {
     print "&lt;p&gt;&lt;span&gt;THANK YOU FOR CONTACTING US!&lt;/span&gt;&lt;/p&gt;";
     print "&lt;p&gt;&lt;span&gt;Someone will get back to you as soon as possible, usually within 48 hours. If you need immediate assistance regarding booking Soul Watt, please call Randy at (828) 729-3199.&lt;/span&gt;&lt;/p&gt;";
     }

 else  {
     print "&lt;p&gt;&lt;span&gt;We encountered an error sending your mail, please notify webmaster@soulwatt.com&lt;/span&gt;&lt;/p&gt;";
     } 
 }
}?&gt;
</code></pre>

<p>Thanks for your help!</p>
