2010-07-26 65 views
0

我覺得我必須在這裏丟失一些簡單的東西......沒有發送,也沒有收到成功的消息。真正基本的幫助w/php聯繫表

<?php 
if(isset($_POST['submit'])) { 
$to = "[email protected]"; 
$subject = "Feedback Form"; 
$name_field = $_POST['name']; 
$email_field = $_POST['email']; 
$message = $_POST['message']; 

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; 

mail($to, $subject, $body); 

$emailSent = true; 
} 
?> 

<!DOCTYPE html> 
<html> 
<head> 
    <title>Feedback Form</title> 

    <link rel="stylesheet" type="text/css" href="style.css" /> 
</head> 
<body> 
    <div id="wrapper"> 

    <h1>Feedback Form</h1> 

    <?php if($emailSent == true) { //If email is sent ?> 
    <p><strong>Feedback Successfully Sent!</strong></p> 
    <?php } else {?> 
    <h3>Please submit your feedback</h3> 
    <?php } ?> 

    <form id="contactForm" action="index.php" method="post"> 

     <label for="name">Name:</label> 
     <input type="text" name="name" id="name" class="required" minlength="2"/> 
     <br/> 
     <label for="email">Email:</label> 
     <input type="text" name="email" id="email" class="required email"/> 
     <br/> 
     <label for="occupation">Occupation:</label> 
     <select name="occupation" id="occupation" class="required"> 
      <option value="librarian">Librarian</option> 
      <option value="student">Student</option> 
      <option value="other">Other</option> 
     </select> 
     <br/> 
     <label for="message">Message:</label> 
     <textarea id="message" class="required" minlength="5"></textarea> 
     <br/> 
     <input class="submit" type="submit" value="Send" /> 


    </form> 


    </div><!--end wrapper--> 

    <script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
     google.load("jquery", "1.4.2"); 
    </script> 
    <script type="text/javascript" src="/js/jquery.validate.pack.js"></script> 
    <script type="text/javascript" src="scripts.js"></script> 
</body> 
</html> 
+0

什麼是真正的問題?你看到什麼問題? – 2010-07-26 17:59:35

回答

1
<input class="submit" type="submit" value="Send" /> 

添加name="submit"以此爲$_POST['submit']進行設置。

編輯:$_POST['message']也可能不存在,因爲它的名稱屬性並未設置。

0

在第一行嘗試使用if (isset($_POST['name']))$_POST['submit']未設置。

+0

或者像Ryan所說的那樣爲輸入按鈕添加一個名稱屬性。問題是現在它不起作用,因爲你沒有'$ _POST ['submit]'。如果你想知道已經發送了什麼參數,可以嘗試'var_dump($ _ POST)'。 – eillarra 2010-07-26 18:08:50