Enquiry.php表单仅与.com电子邮件地址一起使用



仅在用户提交表单的用户使用.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 . 
"rnSurname: " . $surname . 
"rnTelephone Number: " . $telephone . 
"rnEmail Address: " . $email . 
"rnTime 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) {
?>

好的,问题是您的正则

是,当您使用此正则

([w-]+@[w-]+.[w-]+)

它将与此类地址邮件上的结果匹配

billy@hotmail.co.uk

,但匹配的结果将为

billy@hotmail.co

因为您是a_word@a_word.a_word

因此,电子邮件地址根据您的代码有效,但不存在

您必须重新检查正则。

也许尝试

("/.*@.*..*/")

最新更新