嗨我以前使用這個非常簡單的PHP聯繫腳本成功,雖然當我試圖在表單上的新HTML頁面上實現它將不會提交。任何人都可以看到明顯的錯誤? 任何幫助,將不勝感激PHP聯繫表格不提交
這裏是HTML表單:
<div id="formContainer">
<form action="form.php" method="post" id="contactForm">
<fieldset>
<legend>Your details</legend>
<label for="name">Name *</label>
<input type="text" id="name">
<label for="email">Email *</label>
<input type="email" id="email">
<label for="tel">Telephone</label>
<input type="tel" id="tel">
</fieldset>
<fieldset>
<legend>Tutoring</legend>
<label for="type">Type of lesson</label>
<select name="type" id="type">
<option>Individual</option>
<option>Group</option>
</select>
<label for="subject">Subject</label>
<input name="subject" list="subjects" id="subject">
<datalist id="subjects">
<option>English</option>
<option>Biology</option>
<option>Geography</option>
</datalist>
<label for="level">Your level</label>
<select name="level" id="level">
<option>Beginner</option>
<option>GCSE</option>
<option>A-Level</option>
<option>University</option>
</select>
<label for="hours">Hours/week</label>
<input type="number" id="hours">
<label for="info">Additional Information</label>
<textarea name="info" id="info" rows="10" cols="6"></textarea>
</fieldset>
<input type="submit" name="submit" value="Send" id="sendButton">
<input type="hidden" name="submit_check" value="1" />
</form>
</div>
這裏是簡單的PHP腳本:
<?php
if ($_POST["email"]<>'') {
$ToEmail = '[email protected]';
$EmailSubject = 'Site contact form ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY = "Telephone: ".$_POST["tel"]."<br>";
$MESSAGE_BODY = "Type: ".$_POST["type"]."<br>";
$MESSAGE_BODY = "Subject: ".$_POST["subject"]."<br>";
$MESSAGE_BODY = "Level: ".$_POST["level"]."<br>";
$MESSAGE_BODY = "Hours required: ".$_POST["hours"]."<br>";
$MESSAGE_BODY .= "Additional information: ".nl2br($_POST["info"])."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
<html>
<h3>Thanks for your email</h3>
<h4>I'll get back to you as soon as possible</h4>
<a href="index.html"><p>Click here to go back to previous page</p></a>
</html>
<?php
} else {
?>
<html>Sorry, this form didn't work</html>
<?php
};
?>
請注意,除非您正在運行[suhosin](http://www.hardened-php.net/suhosin/configuration.html#suhosin.mail.protect),否則您在此處有可利用的漏洞;攻擊者只需用'\ r \ nCc:blah \ r \ n \ r \ nI Love Spam!'提交'$ _POST [ 電子郵件]]'並且您已將主機變成垃圾郵件。 – sarnold 2011-04-19 10:35:11
是的,我很關心問題是,任何具有任何類型安全功能的腳本似乎都非常複雜,我似乎無法實現它們。我將如何包含suhosin?謝謝 – onjegolders 2011-04-19 11:30:05