表单仅在提交表单的用户使用.com电子邮件地址时才有效。如果用户使用的是.com地址,我会收到一封包含其表单信息(内容)的电子邮件。但是,如果有人使用其他电子邮件地址(例如.co.uk)提交表单,则不会向我发送电子邮件(billy@hotmail.co.uk),请提供帮助。 enquiry.php代码如下:
<?php
$email_to = "billy@hotmail.com";
$firstname = $_POST["firstname"];
$surname = $_POST["surname"];
$telephone = $_POST["telephone"];
$email = $_POST["email"];
$time = $_POST["time"];
if (empty($firstname)) {
show_error("Please fill in your Name - hit back in the browser to correct");
}
if (empty($surname)) {
show_error("Please fill in your Surname - hit back in the browser to correct");
}
if (empty($email)) {
show_error("Please fill in your Email Address - hit back in the browser to correct");
}
if (empty($telephone)) {
show_error("Please fill in your Telephone Number - hit back in the browser to correct");
}
if (empty($time)) {
show_error("Please select a collection time slot - hit back in the browser to correct");
}
$email = htmlspecialchars($_POST['email']);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) {
show_error("E-mail address not valid");
}
$email_from = $_POST["email"];
$message = $_POST["message"];
$email_subject = "Easter 2018 Order Form";
$headers =
"From: $email_from .\n";
"Reply-To: $email_from .\n";
$message =
"First Name: ". $firstname .
"\r\nSurname: " . $surname .
"\r\nTelephone Number: " . $telephone .
"\r\nEmail Address: " . $email .
"\r\nTime Slot: " . $time .
ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $message, $headers, "-f"
.$email_from);
if ($sent) {
header("location:
http://www.billyfarroll.co.uk/thank-you.html");
} else {
echo "There has been an error sending your comments. Please try later.";
}
function check_input($data, $problem='') {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0) {
show_error($problem);
}
return $data;
}
function show_error($myError) {
?>
答案 0 :(得分:0)
好的问题出在你的正则表达式上。
当你使用这个正则表达式
时([\w\-]+\@[\w\-]+\.[\w\-]+)
它会匹配这类地址邮件的结果
billy@hotmail.co.uk
但匹配的结果将是
billy@hotmail.co
因为你要求a_word@a_word.a_word
因此,电子邮件地址根据您的代码有效,但不存在
你必须重新检查你的正则表达式。
也许试试
("/.*@.*\..*/")