0

当我尝试测试它时,它显示Thank you for contacting...... 当我检查我的电子邮件时没有发送任何内容,而且当我输入*$@错误检查似乎忽略它

表格

<h2 class="title"></h2>
<p>&nbsp;</p>
<br />
Please fill out all info below<br /><br />

<form name="Membership Application" action="mailscript.php" method="post">
<table border="1">
  <tr>
    <td><label for="Name">Name</label></td>
    <td width="204"><input type="text" width="200" Name="Name" />&nbsp;</td>
  </tr>
  <TR>
    <TD><input type="submit" name="submit" value="Submit"  /></TD>
    </TR>
</table>
</form>

PHP的

<?php
if(isset($_POST['email'])) {

$email_to = "user@user.com";
$email_subject = "Test";


function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['Name'])) {

    died('We are sorry, but there appears to be a problem with the form you submitted.');      
}

$Name = $_POST['Name']; //required


$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";



//The Error Cheak
if(!preg_match($string_exp,$Name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';;
}
}


if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .="Name: ".clean_string ($Name)."/n";


// create email headers
$headers = 'From: '.$Name."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

还有 7 个信息字段需要填写,但我已将其缩短为 1 个。

4

1 回答 1

0

您的 HTML 中似乎没有名为“电子邮件”的表单输入,因此您的整个错误检查将被跳过,因为从未设置过 $_POST['email']。

于 2012-10-30T10:36:02.270 回答