php联系人表单错误,缺少成功消息

php联系人表单错误,缺少成功消息,php,forms,contact,Php,Forms,Contact,我在发送PHP表单后生成成功或错误消息时遇到问题。电子邮件正确到达,但之后的空白屏幕是一个问题。 <?php if (isset($_POST["submit"])) { $name = $_POST['name']; $email = $_POST['email']; $puhelin = $_POST['puhelin']; $ajankohta = $_POST['aja

我在发送PHP表单后生成成功或错误消息时遇到问题。电子邮件正确到达,但之后的空白屏幕是一个问题。
 <?php
        if (isset($_POST["submit"])) {
            $name = $_POST['name'];
            $email = $_POST['email'];
            $puhelin = $_POST['puhelin'];
            $ajankohta = $_POST['ajankohta'];
            $message = $_POST['message'];
            $human = intval($_POST['human']);
            $from = 'x.fi';
            $to = 'aleksanteri.heliovaara@x.com';
            $subject = 'x ';

            $body ="Nimi: $name\n E-Mail: $email\n Viesti:\n $message\n Ajankohta:\n $ajankohta\n Puhelin:\n $puhelin";

            if (!$_POST['name']) {
                $errName = 'Annan nimesi';
            }
                if (!$_POST['ajankohta']) {
                $errName = 'Anna ajankohta';
            }

            if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                $errEmail = 'Ole hyvä ja anna oikea osoite';
            }
            if (!$_POST['puhelin']) {
                $errName = 'Anna puhelinnumero';
            }

            if (!$_POST['message']) {
                $errMessage = 'Kirjoita viesti';
            }
            if ($human !== 5) {
                $errHuman = 'Your anti-spam is incorrect';
            }
以下是表单标记:

  <div class="contact-form">
    <div class="container">
      <div class="row">
          <div class="col-md-6 col-md-offset-3">
              <h2 class="page-header text-center">Yhteyslomake</h2>
            <form class="form-horizontal" role="form" method="post" action="index.php">
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">Nimesi</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="name" name="name" placeholder="Nimesi" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="email" class="col-sm-2 control-label">Email</label>
                    <div class="col-sm-10">
                        <input type="email" class="form-control" id="email" name="email" placeholder="esimerkki@esimerkki.fi" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="puhelin" class="col-sm-2 control-label">Puhelin</label>
                    <div class="col-sm-10">
                        <input type="" class="form-control" id="puhelin" name="puhelin" placeholder="+358" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="message" class="col-sm-2 control-label">Viesti</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" rows="4" name="message" placeholder="Kerro juhliesi sijainti ja pieni kuvaus"></textarea>
                    </div>
                </div>
                     <div class="form-group">
                    <label for="ajankohta" class="col-sm-2 control-label">Ajankohta</label>
                    <div class="col-sm-10">
                        <input type="" class="form-control" id="ajankohta" name="ajankohta" placeholder="Päivä / Kuukausi / Kellonaika" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="human" name="human" placeholder="Vastauksesi">
                        <p class='text-danger'></p>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <input id="submit" name="submit" type="submit" value="Lähetä" class="btn btn-primary">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

Yhteyslomake
尼梅西
电子邮件
普赫林
维斯蒂
阿詹科塔
2 + 3 = ?

谢谢你的帮助

在单个变量中分配所有错误消息
Assign all error message in single variable 

Ex: $error = array();
if($name == '') {
$error[name] = 'Name is invalid';
}

if($email == '') {
$error[email] = 'Email is invalid';
}

$cErrors = count($errors);

if ($cErrors > 0) {
  echo '<p>Total errors: ' . $cErrors . '</p>';
  $error = '<p>ERROR: Please fill in all required fields!</p>';
  echo "<ul>";
  echo implode("\n", $error);
  echo "</ul>";
}
例如:$error=array(); 如果($name=''){ $error[name]=“名称无效”; } 如果($email=''){ $error[email]=“电子邮件无效”; } $cErrors=计数($errors); 如果($cErrors>0){ 回显“总错误:”.$cErrors.

”; $error='错误:请填写所有必填字段!

'; 回声“
    ”; 回波内爆(“\n”,$error); 回声“
”; }
首先打开错误报告您是回显
$result
,还是仅分配它?如果您不告诉它,它将不会输出任何内容。共享表单标记。@aynber我认为php将呈现文本:“success”或“fail”,而不分配给另一个.html等。您不需要加载另一个html文件。只需回显变量即可。PHP只呈现您告诉它的内容。
Assign all error message in single variable 

Ex: $error = array();
if($name == '') {
$error[name] = 'Name is invalid';
}

if($email == '') {
$error[email] = 'Email is invalid';
}

$cErrors = count($errors);

if ($cErrors > 0) {
  echo '<p>Total errors: ' . $cErrors . '</p>';
  $error = '<p>ERROR: Please fill in all required fields!</p>';
  echo "<ul>";
  echo implode("\n", $error);
  echo "</ul>";
}