Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/12/2011, 10:35
Arkaitz
 
Fecha de Ingreso: agosto-2011
Ubicación: España
Mensajes: 445
Antigüedad: 12 años, 8 meses
Puntos: 89
Respuesta: Formulario en php

Código PHP:
Ver original
  1. <?php
  2.  
  3.  $EmailFrom = "[email protected]";
  4.  $EmailTo = "[email protected]";
  5.  $Subject = "ANDES/HOTEL formulario contacto";
  6.  $nombre = Trim(stripslashes($_POST['nombre']));
  7.  $pais = Trim(stripslashes($_POST['pais']));
  8.  $pasajeros = Trim(stripslashes($_POST['adultos']));
  9.  $pasajeros = Trim(stripslashes($_POST['ninos']));
  10.  $llegada = Trim(stripslashes($_POST['llegada']));
  11.  $salida = Trim(stripslashes($_POST['salida'])) ;
  12.  $tipo_caba = Trim(stripslashes($_POST['tipo_caba']));
  13.  $fono = Trim(stripslashes($_POST['fono']));
  14.  $mail = Trim(stripslashes($_POST['mail']));
  15.  $comentarios = Trim(stripslashes($_POST['comentarios']));
  16.  
  17.  
  18.  // validation
  19.  $validationOK=true;
  20.  if (!$validationOK) {
  21.  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  22.  exit;
  23.  }
  24.  
  25.  // prepare email body text
  26.  $Body = "";
  27.  $Body .= "nombre: ";
  28.  $Body .= $nombre;
  29.  $Body .= "\n";
  30.  
  31.  $Body .= "pais: ";
  32.  $Body .= $pais;
  33.  $Body .= "\n";
  34.  
  35.  $Body .= "adultos: ";
  36.  $Body .= $adultos;
  37.  $Body .= "\n";
  38.  
  39.  $Body .= "niños: ";
  40.  $Body .= $ninos;
  41.  $Body .= "\n";
  42.  
  43.  $Body .= "llegada: ";
  44.  $Body .= $llegada;
  45.  $Body .= "\n";
  46.  
  47.  $Body .= "salida: ";
  48.  $Body .= $salida;
  49.  $Body .= "\n";
  50.  
  51.  $Body .= "tipo cabaña: ";
  52.  $Body .= $tipo_caba;
  53.  $Body .= "\n";
  54.  
  55.  $Body .= "fono: ";
  56.  $Body .= $fono;
  57.  $Body .= "\n";
  58.  
  59.  $Body .= "mail: ";
  60.  $Body .= $mail;
  61.  $Body .= "\n";
  62.  
  63.  $Body .= "comentarios: ";
  64.  $Body .= $comentarios;
  65.  $Body .= "\n";
  66.  
  67.  
  68.  
  69.  // send email
  70.  $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
  71.  
  72.  // redirect to success page
  73.  if ($success){
  74.  print "<meta http-equiv=\"refresh\" content=\"0;URL=gracias.html\">";
  75.  }
  76.  else{
  77.  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  78.  }
  79.  
  80.  if(email==NULL||$fono==NULL) {
  81.  ?>
  82.  <script>
  83.  alert("faltan campos por llenar!");
  84.  location.href="contacto.html";//pagina donde esta tu formulario
  85.  </script>
  86.  
  87.  <?php
  88.  }
  89.  if (!preg_match("/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/", $mail)) {
  90.  exit('El formato del email ingresado no es correcto.');
  91.  }

El if de la línea 80 debería estar antes de la línea 70 que es donde envías el mail. El código lo interpreta de arriba a abajo por eso envía el mail y luego te dice que hay campos por llenar.

y en la línea 80 sería:
Código PHP:
Ver original
  1. if ($email == NULL || $fono == NULL){