嗨,我已经用 php 验证了一个表单,但代码中似乎有问题。验证后它应该发送一封电子邮件,但它没有。这是我的代码:
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$message = $_POST["message"];
$to = "fox.team001@gmail.com";
$subject = $firstName . " " . $lastName;
$headers = "From: fox.team001@gmail.com\r\nReply-To: fox.team001@gmail.com";
validate($firstName , $lastName , $email , $message);
function validate ($firstName , $lastName , $email , $message){
if(!empty($firstName) && !empty($lastName) && !empty($email) && !empty($message)){
if(validateEmail($email)){
$mail_sent = @mail($to , $subject , $message , $headers);
header('refresh:5;url=http://www.foxteam.net');
}else{
header('refresh:0;url=http://www.foxteam.net/contact.php');
}
}else{
header('refresh:0;url=http://www.foxteam.net/contact.php');
}
}
function validateEmail($email) {
$pattern = "^[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-]+\.[A-Za-z0-9]+$";
if(preg_match("/{$pattern}/", $email)) {
return true;
}else{
return false;
}
}