当用户选择与销售额相等的单选按钮时,它会向销售部门发送信息,该工作正常。
当用户选择支持部门时,我需要为他们需要支持的设备输入5位序列号。序列号只能在3到5个数字之间。如果序列不是3到5个数字示例:
在这个框中如果数字是123提交,如果12324提交,如果x3423死,如果12死,如果123456死。我也只需要接受数字。
我可以这样做吗
if($selected == 'sales') {
$body = "From: $name_field\n E-Mail: $email_field\n Address: $address\n City: $city\n State: $state\n PostalCode: $zip\n Department $selected\n How did you about us: $hear\n Country: $country\n Comments: $comment";
mail($to, $subject, $body);
header("Location: http://url/");
}
else if($selected == 'support') {
if(preg_match("/^\d{3}$|^\d{5}$/", $_POST['serial']) === 0) {
$body = "From: $name_field\n E-Mail: $email_field\n Address: $address\n City: $city\n State: $state\n PostalCode: $zip\n Department $selected\n How did you about us: $hear\n Country: $country\n Serial Number: $serial\n Comments: $comment";
mail($toa, $subject2, $body);
header("Location: http://url/");
}
else {
die('<script type="text/javascript"> alert("Serial Number is invalid");</script>');
}
}
}
答案 0 :(得分:2)
如果正则表达式无法匹配,您当前正在发送电子邮件。你的正则表达式也是错的。还有一些小事。
试试这个:
switch($selected) {
case "sales":
$body = "From........................";
mail($to,$subject,$body);
header("Location: .....");
exit;
case "support":
if( preg_match("(^[0-9]{3,5}$)",$_POST['serial'])) {
$body = "From.......................";
mail($toa,$subject2,$body);
header("Location: ......");
exit;
}
else {
die("Serial Number is invalid!");
}
default:
die("Invalid department selection.");
}