Andreii
Новичок
Добрый день, Почему у меня не переправляет на другую страницу ?
PHP:
<?php
function pereprava()
{
header("Location: login.php");
}
?>
<header>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/jquery-1.8.3.js" ></script>
<script type="text/javascript" src="js/jquery.validate.js" ></script>
<script type="text/javascript" src="js/script.js" ></script>
</header>
<body>
<center>
<span class="title" >Обратная связь</span>
</center>
<div id="contact-wrapper">
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"
id="contactform">
<div>
<label for="name"><strong>Name:</strong></label>
<input type="text" size="50" name="contactname"
id="contactname" value="" class="required" />
</div>
<div>
<label for="email"><strong>Email:</strong></label>
<input type="text" size="50" name="email"
id="email" value="" class="required email" />
</div>
<div>
<label for="message"><strong>Message:</strong></label>
<textarea rows="5" cols="50" name="message"
id="message" class="required"></textarea>
</div>
<input type="submit" value="Отправить" name="submit" />
</form>
<?php
//если форма отправлена
if(isset($_POST['submit'])) {
//Проверяем, что поле 'Имя' не пустое
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Проверяем корректен ли введенный почтовый адрес
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$",
trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Проверяем введены ли данные в поле 'сообщение'
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//Если ошибок нет, отправляем форму
if(!isset($hasError)) {
$emailTo = '[email protected]';
//Пропишите здесь ваш почтовый адрес
$body = "Name: $name \n\nEmail: $email
\n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' .
"\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $body, $headers);
$emailSent = true;
}
}
?>
<?php if(isset($hasError)) {
//если найдены ошибки ?>
<p class="error">Пожалуйста, заполните все поля и
введите корректные данные.</p>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) {
//если письмо отправлено
?>
<p><strong>Письмо успешно отправлено!</strong></p>
<p>Спасибо <strong><?php echo $name;?></strong>
за использование контактной формы. Ваше письмо успешно отправлено
и я вскоре с вами свяжусь.</p>
<?php
pereprava();}
?>