如果所选字段没有过帐值,则不发送电子邮件


Form if selected fields have no post value then dont sent email

我有以下代码,检查是否设置了所有变量,只有当isset()的所有参数都设置好时,才会返回true

if (isset($_POST['FirstName'], $_POST['Surname'], 
$_POST['Telephone'], $_POST['email'], $_POST['PickupPoint'],
$_POST['Destination'], $_POST['StartDate'], 
$_POST['NumberofPassengers'])) {
"if all fields have a POST value then send email"
else{
    echo "Please fill in all fields.";
}

然而,即使例如PickupPoint和Destination没有填写,电子邮件也会被发送。

这里的问题是空白字段仍然被视为已设置。您还需要使用例如$_POST['PickupPoint'] !== '' 检查它是否为空

完整示例:

if (isset($_POST['FirstName'], $_POST['Surname'], $_POST['Telephone'], $_POST['email'], $_POST['PickupPoint'], $_POST['Destination'], $_POST['StartDate'], $_POST['NumberofPassengers']) && $_POST['PickupPoint'] !== '' && $_POST['Destination'] !== '') { ...

尽管我建议检查所有字段