我有一個帶有安全問題的簡單表單以防止垃圾郵件。 以問題http://ddry.co.uk/contact_us.html的形式鏈接到我的網頁。如果在聯繫表格輸出中發生錯誤,PHP將顯示一個html頁面
我希望能夠輸出一個HTML頁面,如果用戶輸入一個不正確的答案,而不是純文本。
我有一個重定向到另一個html文件,如果表單成功在我的PHP腳本的底部。看着有人建議使用readfile的其他論壇(「contact-failed.html#fail」);顯示html;不過,我並不完全確定將錯誤答案的重定向代碼放在哪裏。我是PHP新手,所以如果有人能夠解釋我做錯了什麼,那會很好。或者,如果somone擁有更好的垃圾郵件過濾器代碼,那麼這也是非常有用的。
反垃圾郵件的html代碼
PHP文件的後。
----- UPDATE --------
我覺得我後是一個if,else語句? 研究後,我改變了我的代碼,包括一個else語句;然而,由於我缺乏PHP知識,我仍然得到一個空白屏幕,而不是我的錯誤重定向html頁面,它顯示在我的PHP代碼的底部。
問題:如何正確配置if,else語句,如果反垃圾郵件結果錯誤(不等於12),請繼續聯繫failed.html?
在此先感謝
<?php
// Email address verification
function isEmail($clientEmail) {
return filter_var($clientEmail, FILTER_VALIDATE_EMAIL);}
if($_POST) {
// Enter the email where you want to receive the message
$myemail = '[email protected]';
$name = addslashes(trim($_POST['name']));
$clientEmail = addslashes(trim($_POST['email']));
$subject = addslashes(trim($_POST['phone']));
$phone = addslashes(trim($_POST['phone']));
$message = addslashes(trim($_POST['message']));
$antispam = addslashes(trim($_POST['antispam']));
$array = array('nameMessage' => '','emailMessage' => '', 'phoneMessage' => '', 'messageMessage' => '', 'antispamMessage' => '');
if(!isEmail($clientEmail)) {
$array['nameMessage'] = 'Empty name';
}
if(!isEmail($clientEmail)) {
$array['emailMessage'] = 'Invalid email!';
}
if($phone == '') {
$array['phoneMessage'] = 'Empty phone number!';
}
if($message == '') {
$array['messageMessage'] = 'Empty message!';
}
if($antispam != '12') {
$array['antispamMessage'] = 'Incorrect Answer!';
}
if(isEmail($clientEmail) && $clientEmail != '' && $message != '' && $antispam == '12') {
// Send email
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $clientEmail\n Message: \n $message\n Phone: $phone";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $clientEmail";
mail($to,$email_subject,$email_body,$headers);
echo json_encode($array);
header('Location: contact-success.html#success');
}
else (isEmail($clientEmail) && $clientEmail != '' && $message != '' && $antispam !== '12'){
echo('Location: contact-failed.html#fail');}
?>
嘗試是這樣的: 如果($反垃圾郵件= '12'!) { 標題( 「位置:errorpage.html」); } – SamyQc