Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/01/2013, 05:40
marceloangel
 
Fecha de Ingreso: diciembre-2012
Mensajes: 3
Antigüedad: 11 años, 3 meses
Puntos: 0
Respuesta: formulario php da error

Bueno, no era Jquery el formulario, es un js y un php, adjunto el código.

funciones.js

$(document).ready(function(){
$(".boton_envio").click(function() {

var nombre = $(".nombre").val();
email = $(".email").val();
validacion_email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
telefono = $(".telefono").val();
mensaje = $(".mensaje").val();

if (nombre == "") {
$(".nombre").focus();
return false;
}else if(email == "" || !validacion_email.test(email)){
$(".email").focus();
return false;
}else if(telefono == ""){
$(".telefono").focus();
return false;
}else if(mensaje == ""){
$(".mensaje").focus();
return false;
}else{
$('.ajaxgif').removeClass('hide');
var datos = 'nombre='+ nombre +
'&email=' + email +
'&telefono=' + telefono +
'&mensaje=' + mensaje;
$.ajax({
type: "POST",
url: "proceso.php",
data: datos,
success: function() {
$('.ajaxgif').hide();
$('.msg').text('Mensaje enviado!').addClass('msg_ok').animate({ 'right' : '130px' }, 300);
},
error: function() {
$('.ajaxgif').hide();
$('.msg').text('Hubo un error!').addClass('msg_error').animate({ 'right' : '130px' }, 300);
}
});
return false;
}
});
});

/////////////////////////////////////////////////////////////


proceso.php

<?php
// Guardar los datos recibidos en variables:
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$mensaje = $_POST['mensaje'];
// Definir el correo de destino:
$dest = "[email protected]";

// Estas son cabeceras que se usan para evitar que el correo llegue a SPAM:
$headers = "From: $LUPA WINES [email protected]\r\n";
$headers .= "X-Mailer: PHP5\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Aqui definimos el asunto y armamos el cuerpo del mensaje
$asunto = "LUPA WINES / CONTACTO DE PEDIDO";
$cuerpo = "<strong>Nombre:</strong> ".$nombre."<br>";
$cuerpo .= "<strong>Email:</strong> ".$email."<br>";
$cuerpo .= "<strong>Telefono:</strong> ".$telefono."<br>";
$cuerpo .= "<strong>Mensaje:</strong> ".$mensaje;

// Esta es una pequena validación, que solo envie el correo si todas las variables tiene algo de contenido:
if($nombre != '' && $email != '' && $telefono != '' && $mensaje != ''){
mail($dest,$asunto,$cuerpo,$headers); //ENVIAR!
}
?>

/////////////////////////////////////////////////////////////////////////

html

<h1>LUPA WINES</h1>
</blockquote>
<form method="post" class="contacto">
<fieldset>
<div>
<label>Nombre</label>
<input type="text" class="nombre" name="nombre" />
</div>
<div>
<label>Email</label>
<input type="text" class="email" name="email" />
</div>
<div>
<label>Teléfono</label>
<input type="text" class="telefono" name="email" />
</div>
<div>
<label>Mensaje / PEDIDOS</label>
<textarea cols="30" rows="5" class="mensaje" name="mensaje" ></textarea>
</div>
<div class="ultimo"> <img src="codigofuente/ajax.gif" class="ajaxgif hide" />
<div class="msg"></div>
<button class="boton_envio">Enviar Mensaje</button>
</div>
</fieldset>
</form>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="codigofuente/funciones.js"></script>
</div>
</div>