为什么我的联系表格没有发送?

时间:2014-06-08 17:42:34

标签: php html forms email

之前我使用过此联系表单,我刚刚更改了相关信息。出于某种原因现在虽然它不会发送。我浏览了html和php,但我无法看到错误。唯一的区别是,现在我使用的是godaddy,但除此之外,我没有看到错误是什么。帮助!

HTML:

<div id="MainForm">
    <form method="post" action="ContactForm-Handler.php" name="Contact Form" target="_parent" id="ContactForm" title="Contact Form">
      <h1>Contact Form</h1>
      <p>Please fill out information below.</p>
      <p>
        <label for="Name">Name:</label>
        <input type="text" name="Name" id="Name" /><br /><br />
        <label for="Email">Email: </label>
        <input type="text" name="Email" id="Email" /><br /><br />
        <label for="QuestionType">Regarding: </label>
        <select name="QuestionType" id="QuestionType">
          <option value="Products">Products</option>
          <option value="Pricing">Pricing</option>
          <option value="Terms">Terms</option>
          <option value="Other Information">Other</option>
        </select>
        <br /><br />
        <label for="MessageBox">Message: </label>
        <Br /><br />
        <textarea name="MessageBox" cols="50" rows="10">Enter Question/Message Here</textarea>
      </p>
      <p><input name="Send" type="submit" id="Send" onmouseup="ThankYou.html" value="Submit" />
      </p>
  </form>
  </div>

PHP:

<?php 
$errors = '';
$myemail = 'myemail@gmail.com';
$name = $_POST['Name']; 
$email = $_POST['Email']; 
$message = $_POST['MessageBox']; 
$question = $_POST['QuestionType'];
if(!empty($_POST['Products'])) {
    foreach($_POST['Products'] as $products) {
            echo $check; 
    }
}
if(!empty($_POST['Pricing'])) {
    foreach($_POST['Pricing'] as $pricing) {
            echo $check; 
    }
}
if(!empty($_POST['Terms'])) {
    foreach($_POST['Terms'] as $terms) {
            echo $check; 
    }
}
if(!empty($_POST['Other Information'])) {
    foreach($_POST['Other Information'] as $other) {
            echo $check; 
    }
}
if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Contact Form Submission";
    $email_body = "$name needs some information regarding $question \n \n".
    "$message"; 

    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: ThankYou.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>qp Contact Form</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

if(!empty($_POST['Products'])) {
  foreach($_POST['Products'] as $products) {
          echo $check; 
  }
 }
if(!empty($_POST['Pricing'])) {
  foreach($_POST['Pricing'] as $pricing) {
        echo $check; 
  }
 }
if(!empty($_POST['Terms'])) {
  foreach($_POST['Terms'] as $terms) {
         echo $check; 
  }
 }
if(!empty($_POST['Other Information'])) {
  foreach($_POST['Other Information'] as $other) {
         echo $check; 
   }
}

删除此部分代码,因为您需要使用<option>标记的值进行检查。 您应该使用name框中的<select>代替。

像这样:

  //we use name attributes. not value attributes. otherwise $_POST will have Undefined Index error.    
if(!empty($_POST['QuestionType'])){
   foreach($_POST['QuestionType'] as $QuestionType){
        echo $check;
    }
 }

是的,使用php页面顶部的<?php error_reporting(E_ALL); ?>启用php来显示错误。

相关问题