麻烦拍摄PHP表格

时间:2014-01-16 16:43:29

标签: php

我多年来一直使用php联系表单,没有任何问题。现在突然间它会抛出“无效的电子邮件”错误。

以下是处理验证表单字段详细信息的代码部分:

<?php

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

/******** START OF CONFIG SECTION *******/
  $sendto  = "xxxxxxx@xxxxxxxx";
  $subject = "xxxxxxxxxxxxx";
// Select if you want to check form for standard spam text
  $SpamCheck = "Y"; // Y or N
  $SpamReplaceText = "*content removed*";
// Error message if spam form attack found
$SpamErrorMessage = "<p>Malicious code content detected.<br>
Your IP Number of <strong>".getenv("REMOTE_ADDR")."</strong> has been logged.</b></p>";
/******** END OF CONFIG SECTION *******/


  $name = $HTTP_POST_VARS['name']; 
  $email = $HTTP_POST_VARS['email']; 
  $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=utf-8\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 wastign time sending emails
if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();} 

// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer 
  $pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string 

  $name = preg_replace($pattern, "", $name); 
  $email = preg_replace($pattern, "", $email); 
  $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); 
  $name = preg_replace($find, "$SpamReplaceText", $name); 
  $message = preg_replace($find, "$SpamReplaceText", $message); 

// Check to see if the fields contain any content we want to ban
 if(stristr($name, $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 ENQUIRY
----------------------------------------------------------------------------- 

Name: $name 
Email: $email 
Message: $message 

_______________________________________ 
End of Email 
";

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

elseif (!trim($name)) { 
echo "<p>Please go back and enter your <strong>Name<strong>.</p><p><a href='javascript: history.go(-1)'>Click here to go back to the form</a>.</p>"; 
} 

elseif (!trim($message)) { 
echo "<p>Please go back and type a <strong>Message<strong>.</p><p><a href='javascript: history.go(-1)'>Click here to go back to the form</a>.</p>"; 
}  

elseif (!trim($email)) { 
echo "<p>Please go back and enter an <strong>Email<strong>.</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> for taking the time to get in touch. We will get back to you as soon as possible.</p>"; 

} 
} 
else { 
?> 
<p>We are constantly trying to update and improve this site. So if you have any comments or just want to get in touch please fill out the form below. Hopefully the Astropathic Choir will prove strong enough to get it to us.</p>
<p>We do try and get back to everyone, but please be patient as we have other duties too.</p>
<form method="post" autocomplete="off"><INPUT NAME="op" TYPE="hidden" VALUE="send">
<fieldset>
<label for="name">Name:</label>
<input name="name" type="text" placeholder="Your name" size="40" class="text" />
<label for="email">E-mail:</label>
<input name="email" type="email" placeholder="Your email" size="40" maxlength="150" class="text" />
<label for="message">Message:</label>
<textarea name="message" placeholder="What do you want to say?" cols="50" rows="7" class="input"></textarea>
<label>
<input name="submit" type="submit" value="Send" class="button orange send" />
</label>
</fieldset>
</form>
<?php } ?>

它有什么明显的错误吗?如果您需要,我可以提供额外的代码。

非常感谢。

(编辑:根据要求添加完整的表单代码)

0 个答案:

没有答案