【问题标题】:PHP form fields filled emailPHP 表单字段填充电子邮件
【发布时间】:2018-11-23 10:09:30
【问题描述】:

很遗憾,我无法修复此表单,如果字段为空,则不应发送电子邮件

    <?php 
        $to = "info@alpafin.it"; 
        $subject = "Richiesta WEB da WEBFIN"; 
        $body = "Contenuto del modulo:\n\n"; 
        $body .= "Nome: " . trim(stripslashes($_POST["1"])) . "\n"; 
        $body .= "Cognome: " . trim(stripslashes($_POST["5"])) . "\n"; 
        $body .= "Telefono: " . trim(stripslashes($_POST["2"])) . "\n"; 
        $body .= "Email: " . trim(stripslashes($_POST["6"])) . "\n"; 
        $body .= "Provincia: " . trim(stripslashes($_POST["3"])) . "\n"; 
        $body .= "Professione: " . trim(stripslashes($_POST["7"])) . "\n"; 
        $body .= "Importo: " . trim(stripslashes($_POST["4"])) . "\n"; 
        $body .= "Note: " . trim(stripslashes($_POST['8'])) . "\n"; 


        if (!$body || !$cognome || !$Telefono || !$Email !$Provincia || 
        !$Professione || !$Importo || !$Note) {
        echo 'Tutti i campi del modulo sono obbligatori!';    
        }

        ?>

【问题讨论】:

  • $_POST['1'] ... $_POST['8'] 请为您的输入字段提供描述性名称。 $cognome$Telefono 和其他定义在哪里?
  • 你在哪里定义所有这些变量?我只能看到您正在定义$to$subject$body。您的输入名称实际上是否称为1 等?
  • !$body 在这一点上永远不会出现这种情况,因为您在上面的行中填充 $body 有大量内容。
  • 应该是...!$Email || !$Provincia..(缺少||)?

标签: php html forms


【解决方案1】:

在您的代码中,您没有变量 $cogname、$telefono、$email ...。

你应该声明变量

$name = trim(stripslashes($_POST["1"]));
$cognome = trim(stripslashes($_POST["5"]));
$Telefono = trim(stripslashes($_POST["2"]));
$Email = trim(stripslashes($_POST["6"]));
$Provincia = trim(stripslashes($_POST["3"]));
$Professione = trim(stripslashes($_POST["7"]));
$Importo = trim(stripslashes($_POST["4"]));
$Note = trim(stripslashes($_POST["8"]));

这是声明代码。

然后你就可以写了。

if (!$name || !$cognome || !$Telefono || !$Email || !$Provincia ||  !$Professione || !$Importo || !$Note) {
    echo 'Tutti i campi del modulo sono obbligatori!';    
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 2021-07-21
    • 2014-07-08
    相关资源
    最近更新 更多