Здравствуйте! Пытаюсь создать страницу-контактную форму без использования плагина. Код есть вписал:
Это я вставляю в начале файла contacts.php:
<?php
/*
Template Name: Contacts
*/
?>
<?php
if(isset($_POST['submitted'])) {
if(trim($_POST['contactName']) === '') {
$nameError = 'Пожалуйста, введите имя.';
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
if(trim($_POST['email']) === '') {
$emailError = 'Пожалуйста, введите E-Mail адрес.';
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$emailError = 'Вы ввели неправильный E-Mail адрес.';
$hasError = true;
} else {
$email = trim($_POST['email']);
}
if(trim($_POST['comments']) === '') {
$commentError = 'Пожалуйста, введите текст сообщения.';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
if(!isset($hasError)) {
$emailTo = get_option('tz_email');
if (!isset($emailTo) || ($emailTo == '') ){
$emailTo = get_option('admin_email');
}
$subject = '[PHP Snippets] From '.$name;
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
} ?>
<?php get_header(); ?>
И сама контактная форма:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="contact-form" class="three_fourth last_column">
<h5>Отправить сообщение</h5>
<?php if(isset($emailSent) && $emailSent == true) { ?>
<div class="success">Спасибо, ваш сообщение успешно отправлено.</div>
<?php } else { ?>
<?php if(isset($hasError) || isset($captchaError)) { ?>
<div class="error">Извините, произошла ошибка.</div></br>
<?php } ?>
<form action="<?php the_permalink(); ?>" id="contact-form" method="post">
<div class="one_fourth">
<fieldset>
<label>Имя<span class="required">*</span></label>
<input type="text" name="name" id="Myname" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="text requiredField"/>
<?php if($nameError != '') { ?>
<div class="error"><?=$nameError;?></div>
<?php } ?>
</fieldset>
</div>
<div class="one_fourth">
<fieldset>
<label>E-mail<span class="required">*</span></label>
<input type="text" name="email" id="myemail" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="text requiredField email"/>
<?php if($emailError != '') { ?>
<div class="error"><?=$emailError;?></div>
<?php } ?>
</fieldset>
</div>
<div class="one_fourth last_column">
<fieldset>
<label>Тема<span class="required">*</span></label>
<input type="text" name="subject" id="mySubject" value="" class="text requiredField subject"/>
</fieldset>
</div>
<div class="three_fourth">
<fieldset>
<label>Ваше сообщение<span class="required">*</span></label>
<textarea name="message" id="Mymessage" rows="20" cols="30" class="text requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
<?php if($commentError != '') { ?>
<div class="error"><?=$commentError;?></div>
<?php } ?>
</fieldset>
</div>
<div class="one_fourth">
<fieldset>
<input name="Mysubmitted" id="Mysubmitted" value="Отправить сообщение" class="small-button" type="submit"/>
</fieldset>
</div>
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
<?php } ?>
</div>
<!--CONTACT FORM ENDS-->
<?php endwhile; endif; ?>
Но почему-то при отправке вылазит ошибка 404 (404.php)
Помогите пожалуйста, как исправить??