我尝试过更改内容,删除所需部分中的所有内容,以查看表单是否会通过。我被卡住了。目前它只通过通知电子邮件中的电子邮件地址发送。这些领域的其他领域和主题不会出现在电子邮件中。
任何帮助表示赞赏。
<form method="post" action="contact3.php" id="contactformy">
<input type="text" class="textbox" name="contact-name" value="Your Name*" id="contact-name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'contact-name';}">
<input type="text" class="textbox" name="email" value="Your E-mail*" id="email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'email';}">
<input name="Neighbourhood" type="text" class="Subject" value="Neighbourhood" id="neighbourhood" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'neighbourhood';}">
</div>
<textarea placeholder="Your Full Residential Address*" type="text" id="address" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'address';}"></textarea>
<div class="clear"> </div>
<input type="submit" value="SEND MESSAGE">
</div>
</div>
</div>
</form>
这是PHP:
<?php
if(!$_POST) exit;
$email = $_POST['email'];
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('contact-name','email','neighbourhood','address');
$required = array('contact-name','email','address');
$your_email = "lawrencesuss@gmail.com";
$email_subject = "New Message: ".$_POST['neighbourhood'];
$email_content = "new signup:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'contact-name' && $key != 'address') {
if( empty($_POST[$value]) ) {
echo 'PLEASE FILL IN REQUIRED FIELDS';
exit;
}
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content)) {
header('Location: /dankie.html');
} else {
echo 'ERROR!';
}
}
?>
答案 0 :(得分:2)
尝试使用var_dump($ _ POST)查看从表单传递的确切内容。
并检查一下:
<input name="Neighbourhood" [...]" id="neighbourhood"
并在您的PHP脚本中:
$_POST['neighbourhood'];
$ _ POST使用名称值对,它们区分大小写。