I have a problem with my page, I'm sure it's something very simple but I'm not realizing where I have the error. The problem is that the contact form does not work for me, it throws me the following error:
"Sorry, there was an error in your data and the form cannot be submitted at this time. Details of the errors. We are sorry but there seems to be a problem with the data sent. Please correct these errors and try again." And I can't find a way to understand where the error is.
The link of my page is http://indgraphicdesign.com.ar/contacto.html
And here I attach my PHP code:
<?php
if(isset($_POST['email'])) {
$email_to = "
[email protected]";
$email_subject = "Mail de la página";
function died($error) {
// si hay algún error, el formulario puede desplegar su mensaje de aviso
echo "Lo sentimos, hubo un error en sus datos y el formulario no puede ser enviado en este momento. ";
echo "Detalle de los errores.<br /><br />";
echo $error."<br /><br />";
echo "Porfavor corrija estos errores e inténtelo de nuevo.<br /><br />";
die();
}
// Se valida que los campos del formulairo estén llenos
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['message'])) {
died('Lo sentimos pero parece haber un problema con los datos enviados.');
}
//En esta parte el valor "name" nos sirve para crear las variables que recolectaran la información de cada campo
$first_name = $_POST['first_name']; // requerido
$last_name = $_POST['last_name']; // requerido
$email_from = $_POST['email']; // requerido
$telephone = $_POST['telephone']; // no requerido
$message = $_POST['message']; // requerido
$error = ""; //Linea numero 52
//En esta parte se verifica que la dirección de correo sea válida
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'La dirección de correo proporcionada no es válida.<br />';
}
//En esta parte se validan las cadenas de texto
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'El formato del nombre no es válido<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'el formato del apellido no es válido.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'El formato del texto no es válido.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
//A partir de aqui se contruye el cuerpo del mensaje tal y como llegará al correo
$email_message = "Contenido del Mensaje.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Nombre: ".clean_string($first_name)."\n";
$email_message .= "Apellido: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Teléfono: ".clean_string($telephone)."\n";
$email_message .= "Mensaje: ".clean_string($message)."\n";
//Se crean los encabezados del correo
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- incluye aqui tu propio mensaje de Éxito-->
Gracias! Nos pondremos en contacto contigo a la brevedad
<?php
}
?>
$error = "" //Linea numero 52
You are missing a semicolon at the end.
It should stay like this
$error = ""; //Linea numero 52
You updated the question so I'll update my answer below...
First of all the form:
Notice that you have a form inside a form.. =)
Second, in the form, the names of the inputs do not match what the post expects.
Example :
This would be sending the following:
You have to match the variables to the ones you have in this condition:
The PHP isset function is set if that variable exists and is defined, in this case for example
What it is doing is validating if it exists and is defined
$_POST['first_name']
, if the variable is not defined it returns FALSE, therefore the if sends you to the "dead" function.A tip in case you don't realize it is to do the following... In your PHP file to which you send the form above all, do a print to the $_POST to see what it is returning and add an exist so that it only shows that :P
Cheers,