Help! This contact form keeps displaying the error for an invalid email address, no matter what I do! Where did I go wrong?

Thanks in advance!

PHP Syntax

<table width="570px" border="0" cellspacing="10px" cellpadding="0" align="center">
  <tr>
    <td align="center">

<?php 
if (isset($_POST["op"]) && ($_POST["op"]=="send")) { 

/******** START OF CONFIG SECTION *******/
  $sendto  = "mail@mail.com";
  $subject = "Website Contact";
// Select if you want to check form for standard spam text
  $SpamCheck = "Y"; // Y or N
  $SpamReplaceText = "*content removed*";
// Error message printed if spam form attack found
$SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.
</font><br><b>Your IP Number of <b>".getenv("REMOTE_ADDR")."</b> has been logged.</b></p>";
/******** END OF CONFIG SECTION *******/
 
  $indivor = $HTTP_POST_VARS['indivor'];
  $reques = $HTTP_POST_VARS['reques'];
  $relat = $HTTP_POST_VARS['relat'];
  $ship = $HTTP_POST_VARS['ship']; 
  $email = $HTTP_POST_VARS['email']; 
  $phone = $HTTP_POST_VARS['phone'];
  $inreq = $HTTP_POST_VARS['inreq'];
  $message = $HTTP_POST_VARS['message']; 
  $headers = "From: $email\n";
  $headers . "MIME-Version: 1.0\n"
		   . "Content-Transfer-Encoding: 7bit\n"
		   . "Content-type: text/html;  charset = \"iso-8859-1\";\n\n";
if ($SpamCheck == "Y") {		   
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wasting time sending emails
if (preg_match("/http/i", "$indivor")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$reques")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$relat")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$ship")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$phone")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$inreq")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();} 

// Pattern match search to strip out the invalid characters, this prevents the mail injection spammer 
  $pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string 
                            
  $indivor= preg_replace($pattern, "", $indivor);
  $reques= preg_replace($pattern, "", $reques); 
  $relat = preg_replace($pattern, "", $relat); 
  $ship = preg_replace($pattern, "", $ship); 
  $email = preg_replace($pattern, "", $email); 
  $phone = preg_replace($pattern, "", $phone);
  $inreq = preg_replace($pattern, "", $inreq);
  $message = preg_replace($pattern, "", $message); 

// Check for the injected headers from the spammer attempt 
// This will replace the injection attempt text with the string you have set in the above config section
  $find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i"); 
  $email = preg_replace($find, "$SpamReplaceText", $email); 
  $indivor = preg_replace($find, "$SpamReplaceText", $indivor); 
  $reques = preg_replace($find, "$SpamReplaceText", $reques); 
  $relat = preg_replace($find, "$SpamReplaceText", $relat);
  $ship = preg_replace($find, "$SpamReplaceText", $ship);
  $phone = preg_replace($find, "$SpamReplaceText", $phone); 
  $inreq = preg_replace($find, "$SpamReplaceText", $inreq); 
  $message = preg_replace($find, "$SpamReplaceText", $message); 
  
// Check to see if the fields contain any content we want to ban
 if(stristr($indivor, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($reques, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($relat, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($ship, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($phone, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($inreq, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
 if(stristr($message, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 
 // Do a check on the send email and subject text
 if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($subject, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
}
// Build the email body text
  $emailcontent = " 
----------------------------------------------------------------------------- 
  Website Contact
----------------------------------------------------------------------------- 

For an Individual? Or a Group? $indivor
Requested By: $reques
Relationship to child or group: $relat
Address to ship instrument: $ship 
Phone Number: $phone 
Email: $email 
Instrument(s) Requested: $inreq 
Other Information: $message 

_______________________________________ 
End of Email 
"; 
// Check that the email address entered matches the standard email address format
 if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { 
  echo "<p>ERROR! It appears you entered an invalid email address.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($indivor)) { 
  echo "<p>ERROR! Please go back and enter if you are an Individual or a Group.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($reques)) { 
  echo "<p>ERROR! Please go back and enter Requested By.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($relat)) { 
  echo "<p>ERROR! Please go back and enter Relationship To.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($ship)) { 
  echo "<p>ERROR! Please go back and enter Address To Ship.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($email)) { 
  echo "<p>ERROR! Please go back and enter an Email address.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($phone)) { 
  echo "<p>ERROR! Please go back and enter a Phone Number.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($inreq)) { 
  echo "<p>ERROR! Please go back and fill in the Instrument Request field.</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

// Sends out the email or will output the error message 
 elseif (mail($sendto, $subject, $emailcontent, $headers)) { 
  echo "<br><br><p><b>Thank You $name</b></p><p>We will be in touch as soon as possible.</p>"; 

} 
} 
else { 
?> 

<p align="left">Musical Instrument Request Form
<br /><br />
NOTE: If Individual child request, please provide music teacher name and contact information in your message.
<br /><br />
Please complete all the information and we will get back to you shortly.</p>
<br>
<form method="post"><INPUT NAME="op" TYPE="hidden" VALUE="send"> 
  <table> 
    <tr> 
      <td><p>For an Individual? Or a Group?</p></td> 
      <td> 
        <input name="indivor" type="text" size="30" maxlength="25"> 
      </td> 
    </tr>

    <tr> 
      <td><p>Requested By:</p></td> 
      <td> 
        <input name="reques" type="text" size="30" maxlength="150"> 
      </td> 
    </tr> 
	
    <tr> 
      <td><p>Relationship to child or group:</p></td> 
      <td> 
        <input name="relat" type="text" size="30" maxlength="150"> 
      </td> 
    </tr>
	
    <tr> 
      <td><p>Address to ship instrument:</p></td> 
      <td> 
        <input name="ship" type="text" size="30" maxlength="300"> 
      </td> 
    </tr> 
	
    <tr> 
      <td><p>Phone Number:</p></td> 
      <td> 
        <input name="phone" type="text" size="30" maxlength="150"> 
      </td> 
    </tr> 
	
    <tr> 
      <td><p>E-mail:</p></td> 
      <td> 
        <input name="email" type="text" size="30" maxlength="150"> 
      </td> 
    </tr> 
	
    <tr> 
      <td><p>Instrument(s) Requested:</p></td> 
      <td> 
        <input name="inreq" type="text" size="30" maxlength="150"> 
      </td> 
    </tr> 
	
    <tr> 
      <td valign="top"><p>Other Information:</p></td> 
      <td><textarea name="message" cols="40" rows="6"></textarea></td> 
    </tr> 
    <tr><td></td> <td><input name="submit" type="submit" value="Send Message"></td></tr> 
  </table> 
</form> 
<?php } ?>

  </td>
  </tr>
</table>
Member Avatar for P0lT10n

noooooo, dont post your code like text... use [code] tags...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.