有人可以告訴我我的代碼有什麼問題。我無法弄清楚錯誤是什麼。html和php聯繫表單故障
接觸形式
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="telephone">
<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call">
No:<input type="checkbox" value="No" name="call"><br />
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">General Enquiries</option>
</select>
<br />
<p>Message</p><textarea name="message" rows="10" cols="40"></textarea><br />
<input type="submit" value="Send" class="button"/><input type="reset" value="Clear" class="button"/>
</form>
mail.php
<?php
if(isset($_POST['email'])) {
$email_to = "[email protected]";
$email_subject = "Tip Top Music";
function died($error) {
// Error codes
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// Required fields
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
died('Required Fields are not complete');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
if(!isset($_POST['call'])) {
$call = "No"; // if checkbox was left unchecked. Default is No
}
else {
$call = ($_POST['call'])
}
$priority = $_POST['priority']; // Will already have default value
$type = $_POST['type']; // Will already have default value
$message = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Request Callback: ".($call)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Priority: ".($priority)."\n";
$email_message .= "Type: ".($type)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- Message success -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
我得到了一個未定義指數看漲指向$調用= 「否」;線。但是腳本甚至不應該運行,因爲我發佈了一個空白表單?當我回顯輸入字段時,它們是空白的,但是如果放入IF語句來檢查它們是否被設置(isset),它會進入語句,就好像它們已被設置一樣?我應該使用isset以外的東西來檢查空輸入嗎?這通常很困惑,爲什麼它現在不是?
@vinodadhikary你是什麼意思?死了就是那裏的一個函數的名字 – ToniHopkins
抱歉沒有注意到! – vee
關於表格:'請求電話'部分是一個是/否的問題。使用任一複選框或兩個單選按鈕。不要使用兩個複選框。 – Theox