我已經設置了一個簡單的聯繫表單,但在收尾過程中遇到了一些麻煩。每當提交表單時,我都會收到錯誤消息。希望有人可以看看我的代碼並指出我的錯誤。謝謝!聯繫表格提交錯誤
(編輯)忘了提及的錯誤是,一旦表單被提交,我被重定向到錯誤頁面(error.html),而不是成功(contactthanks.php)頁面。
HTML:
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
PHP:
<?php
$EmailFrom = "";
$EmailTo = "[email protected]";
$Subject = "";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
}
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
...錯誤是? –
你從這得到了什麼錯誤? – Gaurav
我想你只是給變量和輸入類型命名。嘗試不同的名字。像$ name = Trim(stripslashes($ _ POST ['Name'])); smaill'name'而不是大寫'Name'。 希望它有幫助。 – Gaurav