简单地说,我找到了这段代码来验证电子邮件:
filter_var($user_email, FILTER_VALIDATE_EMAIL)
但不幸的是,我不知道如何将其添加到从表单获取信息的 PHP 代码中:
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "example@example.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
我使用 Ajax 来获取表单的提交信息。