у меня есть форма contact.php, которая работает очень хорошо, но у меня проблема с этой формой, такие сообщения, как оповещения и т. д., отображаются в самом файле contact.php, я хочу, чтобы, когда я нажимаю кнопку «Отправить», php ставит eccho, чтобы сказать сообщение, не покидая сайт.
Вот мой contact.php
<?php
if(isset($_POST['email'])) {
$email_to = "[email protected]";
$email_subject = "Nuevo contacto de Sitio web";
function died($error) {
// Mensaje de error
echo "Disculpas, pero ha ocurrido un(os) error(es) con lo datos del formulario. ";
echo "El o los errores son los siguientes.<br /><br />";
echo $error."<br /><br />";
echo "Por favor corrija los errores.<br /><br />";
die();
}
// validacion de campos
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
died('Disculpas, pero ha ocurrido un(os) error(es) al enviar el formulario.');
}
$name = $_POST['name']; // obligatorio
$email = $_POST['email']; // obligatorio
$website = $_POST['website']; // no obligatorio
$prioritycase = $_POST['prioritycase']; // no obligatorio
$asunto = $_POST['asunto']; // no obligatorio
$message = $_POST['message']; // obligatorio
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'La direccion de E-mail es incorrecta.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'EL nombre no es un nombre Valido.<br />';
}
if(!preg_match($string_exp,$website)) {
$error_message .= 'La url no es valida.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'El comentario no parece estar completo.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Nombre: ".clean_string($name)."\n";
$email_message .= "Website: ".clean_string($website)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Mensaje: ".clean_string($message)."\n";
// estructura del correo
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<meta http-equiv="refresh" content="3;URL=http://www.redpandastudio.tk" />
<link rel="stylesheet" type="text/css" href="dist/css/contacto.css" />
<!-- incluimos nuestro mensaje de agradecimiento -->
<?php
}
?>
И вот мой сайт с рабочей формой обратной связи.
error
, а на странице первым делом проверьте, установлена ли ошибка этого параметра - отобразите ошибку. - person Nir Alfasi   schedule 24.01.2014