我已使用this sample by CSS-Tricks創建了一個簡單的聯繫表單。它工作得很好,直到我定製了contactthanks.php
頁面(成功提交表單的確認)。現在,每次用戶點擊「提交」時,他們都會重定向到錯誤頁面。表單'提交'按鈕始終以錯誤結尾
住的頁面:alookat.org/contact.html(隨意測試表格)。
以下是contactengine.php
在編輯之後破壞了內容。我刪除了電話輸入並將其替換爲網站。我也重新編排了投入。
<?php
$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "Thanks for contacting us";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Website = Trim(stripslashes($_POST['Website']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=php\contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
感謝您的幫助。謝謝閱讀。
使用「下面是它打破東西后,我編輯它contactengine.php。」如何打破事情?你確切的問題是什麼? – Shaggy
您應該使用'echo'而不是'print' - 與(print)不同,它(稍微)更快,並且不會返回值。 – Chad