提交 php 表格后,我得到空 window 并且没有电子邮件

After submiting a php form I get empty window and no e-mail

更新:

我在代码末尾添加了 echo $errors。现在我知道所有字段都是必需的,尽管所有字段都已填写:

} else {
  echo $errors;
}

我用这个例子 (link). And jQuery form validator (link) 创建了一个简单的 php 电子邮件表单。

现在我提交表单后得到的只是一个空白的 "contact-form-handler.php" 页面。

您可以在以下位置查看实时表格:mantasmilka.com/#contactPage

可能是什么问题?下面是我的代码。

联系表-handler.php

<?php
$errors = '';
$myemail = 'mantas@mantasmilka.com';//<-----Put Your email address here.
if(empty($_POST['infoname'])  ||
   empty($_POST['infocompany']) ||
   empty($_POST['infoemail']) ||
   empty($_POST['infophone']) ||
   empty($_POST['infodescription'])
   )
{
    $errors .= "\n Error: all fields are required";
}
$jobtype = $_POST['jobtype'];
$budget = $_POST['budget'];
$location = $_POST['location'];

$infoname = $_POST['infoname'];
$infocompany = $_POST['infocompany'];
$infoemail = $_POST['infoemail'];
$infophone = $_POST['infophone'];

if (isset($_POST['infodescription'])) {
    $infodescription = $_POST['infodescription'];
}

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$infoemail))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Jobtype: $jobtype \n Budget: $budget \n Location: $location \n Name: $infoname \n Company: $infocompany \n E-mail: $infoemail \n Phone: $infophone \n ".
"Message \n $infodescription";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $infoemail";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
// header('Location: http://www.mantasmilka.com/index.php');
header('Location: index.php');
exit();
} else {
  echo $errors;
}
?>

我在 index.php 中的表格:

  <form id="contactform" method="post" name="contact_form" action="contact-form-handler.php">
    <div class="left">
      <fieldset class="jobtype">
        <legend>Job type</legend>
        <input type="radio" name="jobtype" id="project" value="project" required>
          <label for="project">Project</label>
        <input type="radio" name="jobtype" id="part-time" value="part-time" >
          <label for="part-time">Part-time</label>
        <input type="radio" name="jobtype" id="full-time" value="full-time" >
          <label for="full-time">Full-time</label>
      </fieldset>
      <fieldset class="budget">
        <legend>Budget</legend>
        <input type="radio" name="budget" id="budget5k" value="budget5k" required>
          <label for="budget5k">5k &euro; ></label>
        <input type="radio" name="budget" id="budget10k" value="budget10k" >
          <label for="budget10k">5k - 10k &euro;</label>
        <input type="radio" name="budget" id="budget15k" value="budget15k" >
          <label for="budget15k">15k &euro; <</label>
      </fieldset>
      <fieldset class="location">
        <legend>Location</legend>
        <input type="radio" name="location" id="locremote" value="locremote" required>
          <label for="locremote">Remote</label>
        <input type="radio" name="location" id="loclocal" value="loclocal" >
          <label for="loclocal">Local with relocation</label>
      </fieldset>
    </div>
    <div class="right">
      <fieldset class="contactinfo">
        <legend>Your Contact Info</legend>
        <div class="input-holder">
          <input type="text" name="infoname" id="infoname" value="" required data-validation="alphanumeric">
          <label for="infoname">Name</label>
        </div>
        <div class="input-holder">
          <input type="text" name="infocompany" id="infocompany" value="" required data-validation="alphanumeric">
          <label for="infocompany">Company</label>
        </div>
        <div class="input-holder">
          <input type="text" name="infoemail" id="infoemail" value="" required data-validation="email">
          <label for="infoemail">E-mail</label>
        </div>
        <div class="input-holder">
          <input type="text" name="infophone" id="infophone" value="" required data-validation="number">
          <label for="infophone">Phone</label>
        </div>
        <div class="input-holder textarea">
          <textarea name="infodescription" form="contact_form" rows="4" required></textarea>
          <label for="infodescription">Message</label>
        </div>
        <div class="input-holder submit">
          <input type="submit" name="submit" value="Submit" required/>
        </div>
      </fieldset>
    </div>
  </form>

文本字段应如下所示不要在此处放置表单标签

<textarea name="infodescription" rows="4" required></textarea>

在 php 中首先创建这样的 if 语句(最后打开 if 语句)关闭它并且不要考虑我如何使用其他括号

if(
   (empty($_POST['infoname']))  ||
   (empty($_POST['infocompany'])) ||
   (empty($_POST['infoemail'])) ||
   (empty($_POST['infophone'])) ||
   (empty($_POST['infodescription']))
   )
     {
      $errors .= "\n Error: all fields are required";
     }

解决问题的有效方法是:

$('#contactform').submit(function(ev) {
    ev.preventDefault(); 
    if($('#infodescription').val() == '')
    {
     alert('Description is required');
     return false;
    }
    //add other validation
    this.submit(); // If all the validations succeeded
});

这样可以避免不必要的服务器负载。