形式
<form id="contact" action="" method="post">
<input id="name" type="text" name="name" width="250" size="35" placeholder="Your name" required/>
<br><br>
<input id="email" type="text" name="email" width="250" size="35" placeholder="Your mail" required/>
<br><br>
<textarea id="message" name="message" rows="6" cols="40" placeholder="Your message" required></textarea>
<br><br>
<input type="button" value=" SEND " id="submit" />
<input type="reset" value="Reset" name="reset">
<div id="success"></div>
</form>
js
$('#submit').click(function(){
$.post("chapters/contactphp.php", $("#contact").serialize(), function(response) {
$('#success').html(response);
});
return false;
});
php
if((empty($_POST['name'])) || (empty($_POST['email'])) || (empty($_POST['message']))){
die("All fields must be filled !");
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'qadenza@gmail.com';
$subject = 'stojada contact';
$message = 'FROM: '.$name." \nEmail: ".$email."\nMessage: \n".$message;
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
mail($to, $subject, $message);
echo "Thank you! Your email was sent.";
}else{
echo "The email you entered, is not valid.";
}
所有字段均已填充,但 echo 为All fields must be filled
.