php发布表单没有通过电子邮件发送或检查错误

时间:2012-10-30 10:22:40

标签: php

当我尝试测试时,会显示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。

1 个答案:

答案 0 :(得分:0)

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