我這個[教程]提出的驗證碼[1],添加簡單的數學驗證碼
[1]:http://codechirps.com/how-to-add-a-completely-custom-captcha-to-any-web-form/,但在我看來,它不完整。 我做了代碼,但我可以發送電子郵件,即使我提出錯誤的答案。我覺得我必須在PHP文件中編寫額外的代碼,但我不知道在哪裏。任何幫助大大appriciated
<div class="modal-body">
<form class="contact" name="contact">
<label class="label" for="name">Имя</label><br>
<input type="text" name="name" class="input-xlarge"><br>
<label class="label" for="email">E-mail</label><br>
<input type="email" name="email" class="input-xlarge"><br>
<label class="label" for="message">Сообщение</label><br>
<textarea name="message" class="input-xlarge"></textarea>
</form>
</div>
<div class="modal-footer">
<p>2 + 3 =</p>
<input type="text" name="captcha" />
<input class="btn btn-warning" type="submit" value="Отправить" id="submit">
<a href="#" class="btn btn-danger" data-dismiss="modal">Закрыть</a>
<?php
$myemail = '';
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
$captcha = check_input($_POST['captcha']);
echo "<span class=\"alert alert-success\" >Сообщение отправлено</span><br><br>";
if (!preg_match("/5/", $captcha))
{
show_error("Check your math, Dude");
}
$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: $email\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
}?>
那是因爲你沒有驗證'email'字段。而對於驗證碼..函數check_input做什麼?此外,您的驗證碼字段不在表單中。普韋凡德,謝謝你的回答。請告訴我,如果可能的話,我需要做些什麼來驗證電子郵件字段?我通過教程做了,並認爲check_input檢查captcha字段 – putvande
PHP中檢查電子郵件的最簡單方法是做'filter_var($ _ POST ['email'],FILTER_VALIDATE_EMAIL)' – jdepypere
請告訴我,我需要什麼把這個放在我的php文件 – Lucky