У меня есть контактная форма по адресу http://www.kaimeramedia.com/derek/Website/contact.php. Я проверил свой код PHP на PHPcodechecker.com, и он говорит, что синтаксических ошибок нет. Я думаю, что начальный код работает в каком-то поместье, потому что каждый раз, когда я нажимаю «Отправить», он переходит к следующей проверке, где я остаюсь с: «Обнаружен неправильный адрес электронной почты. Пожалуйста, нажмите кнопку «Назад» в браузере и повторите попытку».
Я просто хочу знать, должен ли я писать код по-другому, чтобы убедиться, что проверка электронной почты прошла и разрешила отправку сообщения. Я не уверен, что у меня что-то закодировано наоборот. Я перепробовал много комбинаций, но в нынешнем виде это самая дальняя из тех, что мне удалось пройти без ошибки mailform.php. Код для файла mailform.php:
<?php
session_start();
$dontsendemail = 0;
$possiblespam = FALSE;
$strlenmessage = "";
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$message = $_REQUEST['message'];
$subject = "Regarding Your Portfolio";$emailaddress = "[email protected]";
// checks if name field is empty
function checkname() {
if (empty($name)) {
die ("You did not enter your name. Please hit your browser back button and try again.");
return 1;
}
}
// checks if the captcha is input correctly
function checkcaptcha() {
if ($_SESSION["pass"] != $_POST["userpass"]) {
die("Sorry, you failed the CAPTCHA. Note that the CAPTCHA is case-sensitive. Please hit your browser back button and try again.");
return 1;
}
}
// checks proper syntax
function checkemail() {
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email));
else{
die("Improper email address detected. Please hit your browser back button and try again.");
return 1;
}
}
function spamcheck($field) {
if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%0A",$field)){
$possiblespam = TRUE;
}else $possiblespam = FALSE;
if ($possiblespam) {
die("Possible spam attempt detected. If this is not the case, please edit the content of the contact form and try again.");
return 1;
}
}
function strlencheck($field,$minlength,$whichfieldresponse) {
if (strlen($field) < $minlength){
die($whichfieldresponse);
return 1;
}
}
if ($dontsendemail == 0) $dontsendemail = checkcaptcha($email);
if ($dontsendemail == 0) $dontsendemail = checkemail($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($name);
if ($dontsendemail == 0) $dontsendemail = strlencheck($email,10,"The email address field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($message,10,"The message field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($emailaddress,8,"You have not selected a recipient of your message. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($name,3,"The Name field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) {mail($emailaddress,"Subject: $subject",$message,"From: $name,$email" ); include "thankyou.php";}
?>
Я поместил фиктивный адрес электронной почты в этот код, но настоящий находится в файле mailform.php. Если кто-нибудь увидит, где я ошибся, буду очень признателен.