有人可以幫我解決這個問題嗎?在Php聯繫表中添加垃圾郵件控制
我想將此代碼添加到我的聯繫表單,以防止垃圾郵件,但它不起作用。
HTML:
Access code: <input type="text" name="code" /><br />
請輸入上面mycode的。
PHP的:
if (strtolower($_POST['code']) != 'mycode') {die('Wrong access code');}
這樣的問題是因爲某些原因沒有進行重定向回謝謝網頁代碼是否正確。
這裏是我試圖使它的工作:
if (strtolower($_POST['code']) == 'mycode')
header('Location: ../thank-you.php');
exit('Redirecting you to ../thank-you.php');
if (strtolower($_POST['code']) != 'mycode')
{
die('Wrong access code! Please go back and try again.');
exit;
}
這裏是PHP的全部代碼:
<?php
require_once('class.phpmailer.php');
include("class.smtp.php");
$myaddress = "[email protected]";
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$lastname = $_POST['lastname'];
$bizphone = $_POST['bizphone'];
$state = $_POST['state'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$code = $_POST['code'];
//This line is checking the input named code to verify humans
if (strtolower($_POST['code']) == 'mycode') {
header('Location: ../thank-you.php');
exit('Redirecting you to ../thank-you.php');
}
if (strtolower($_POST['code']) != 'mycode')
{
die('Wrong access code! Please go back and try again.');
exit;
}
// This code checks the hidden fields only bots can fill to verify humans
if(strlen($lastname) !== 0)
{
header('Location: ../thank-you.php');
exit;
}
if(strlen($bizphone) !== 0)
{
header('Location: ../thank-you.php');
exit;
}
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$mailst = $_POST['mailst'];
$emailbody = "
<p>You have received a Quote !</p><br />
<p><strong>First - Last Name:</strong> {$name} </p>
<p><strong>Email Address:</strong> {$email} </p>
<p><strong>Telephone:</strong> {$phone} </p>
<p><strong>Additional Comments:</strong> {$comments}</p>
<p><strong>Ip Address:</strong> {$ip}</p>
<p><strong>Refererer:</strong> {$httpref}</p>
<p><strong>User Agent:</strong> {$httpagent}</p>
";
class myphpmailer extends PHPMailer
{
// Set default variables for all new objects
public $From = "";
public $FromName = "";
public $Sender = "";
//public $Subject = $quoterequest;
public $Host = '';
public $Port = ;
public $SMTPSecure = 'ssl';
public $SMTPAuth = true;
public $Username = '';
public $Password = '';
}
$mail = new myphpmailer;
#!!!!!CHANGE SMTPDebug level for debugging!!!
$mail->SMTPDebug = 0;
$mail->Subject = "Contact Form";
$mail->IsSMTP();
$mail->AddAddress($myaddress);
$mail->MsgHTML($emailbody);
$mail->SMTPAuth = true;
$mail->Send();
exit(header("Location: ../thankyou.php"));
?>
我只需要一個方法來驗證人類或塊的機器人,但如果兩個將工作它將是真棒:)
謝謝。
的原始意見,我改變了這種代碼。請檢查這個新的代碼。 –
你是這個問題。必須更改{} –
並添加此{header('Location:../thank-you.php'); exit('將您重定向到../thank-you.php'); } –