maxuber Posted December 21, 2012 Report Share Posted December 21, 2012 Amigos, recurro a ustdes para ver si este formulario esta bien hecho o le faltan script para mejorar su envío. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" <html xmlns="http://www.w3.org/1999/xhtml" lang="cl" xml:lang="cl"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>tittle</title> </head> <body> <?php if(isset($_POST['submit'])){$errors = array();//declaramos un array para almacenar los erroresif($_POST['nombre'] ==''){$errors[1] ='<span class="error">Ingrese su nombre</span>';}else if($_POST['email'] =='' or !preg_match("/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/",$_POST['email'])){$errors[2] ='<span class="error">Ingrese su email correcto</span>';}else if($_POST['empresa'] ==''){$errors[3] ='<span class="error">Ingrese una empresa</span>';}else if($_POST['telefono'] ==''){$errors[4] ='<span class="error">Ingrese su telefono</span>';}else if($_POST['coment'] ==''){$errors[5] ='<span class="error">Ingrese su mensaje</span>';}else {//si todo esta ok envia email /* Recepcionamos los datos enviados asincrnicamente */ $nombre = $_POST['nombre'];$email = $_POST['email'];$empresa = $_POST['empresa'];$telefono = $_POST['telefono'];$comentario = $_POST['coment'];$fecha = date("d-m-Y"); $hora = date("H:i:s"); /* Definimos el correo donde enviaremos el mensaje y el asunto */ $destino = "[email protected]";$asunto = "CONTACTO SITIO WEB ";$de ="[email protected]";$asunto2 ="GRACIAS POR CONTACTARNOS ";$copia ="[email protected]";/* Definimos el formato del mensaje a enviar */ $cuerpo = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//ES" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>Documento sin título</title></head> <body style="border:0px; margin:0px; background-color:#EBEBEB;"> <table width="350" border="0" align="center" cellpadding="0" cellspacing="5" bgcolor="#666666" style="margin-top:25px;"> <tr align="center"> <td><table width="350" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td height="30" colspan="2" align="left"> <h2 style="font-family:Tahoma, Geneva, sans-serif; font-size:18px; color:#666; margin-left: 10px; text-decoration:underline">Datos del usuario</h2></td> </tr> <tr> <td width="120" height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:14px; color:#666; margin-left:10px; font-weight: bold;">Nombre:</p></td> <td width="230" height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#999; margin-left:10px;">'.$nombre.'</p></td> </tr> <tr> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:14px; color:#666; margin-left:10px; font-weight: bold;">Email:</p></td> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#999; margin-left:10px;">'.$email.'</p></td> </tr> <tr> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:14px; color:#666; margin-left:10px; font-weight: bold;">Empresa:</p></td> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#999; margin-left:10px;">'.$empresa.'</p></td> </tr> <tr> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:14px; color:#666; margin-left:10px; font-weight: bold;">Teléfono:</p></td> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#999; margin-left:10px;">'.$telefono.'</p></td> </tr> <tr> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:14px; color:#666; margin-left:10px; font-weight: bold;">Fecha de envío:</p></td> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#999; margin-left:10px;">'.$fecha.'</p></td> </tr> <tr> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:14px; color:#666; margin-left:10px; font-weight: bold;">Hora de envío:</p></td> <td height="20" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#999; margin-left:10px;">'.$hora.'</p></td> </tr> <tr> <td height="10" colspan="2" align="center">---------------------------------------------------</td> </tr> <tr> <td height="30" colspan="2" align="left"><h2 style="font-family:Tahoma, Geneva, sans-serif; font-size:18px; color:#666; margin-left: 10px; text-decoration:underline">Consulta</h2></td> </tr> <tr> <td colspan="2" align="left"><p style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#999; margin-left:10px; margin-top:3px; margin-bottom:10px;">'.$comentario.'</p></td> </tr></table> </td> </tr></table></body></html>'; /* Definimos las cabeceras del mensaje */ $cabecera = "MIME-Version: 1.0\r\n";$cabecera .= "Content-type:text/html; charset=UTF-8\r\n";$cabecera .= "From: $email\r\n";$cabecera .= "Reply-to: $email\r\n";$cabecera .= "X-Mailer: PHP5\r\n";$cabecera .= "Cc: $copia\r\n"; /* Enviamos va correo, devolviendo un mensaje en caso de xito o falla */ if(mail($destino, $asunto, $cuerpo, $cabecera)) {$result = '<div class="result_ok">Email enviado correctamente</div>';// si el envio fue exitoso reseteamos lo que el usuario escribio:$_POST['nombre'] = ''; $_POST['email'] = ''; $_POST['empresa'] = ''; $_POST['telefono'] = '';$_POST['coment'] = '';}else{$result = '<div class="result_fail">Hubo un error al enviar el mensaje</div>';}}mail($email, $asunto2, "Estimado(a) $nombre:\r\rGracias por tu visita, hemos recibido su consulta y pronto seras contactado por nuestros ejecutivos. \rRecuerda que para asegurar la entrega de nuestros e-mail en tu correo, por favor agrega ([email protected]) a tu libreta de direcciones o revisa tambin tu carpeta spam o carpeta Junk Email. \r\rSaludos,\rMi Empresa \r Servicio al Cliente \rTel. 1234 56 78\remail: [email protected]\r\r---\r LALALALALALALALA\r{LALALALALALALALALALALALALLALALALALALALALLA.}","From: $de"); }?> <div id="wrapper-form"> <form action="" method="post" class="contacto"> <div><label>Tu nombre</label> <input name='nombre' type='text' id='nombre' value='<?php echo $_POST['nombre']; ?>' size='32' class='nombre' /> <?php echo $errors[1]; ?></div> <div><label>Tu email</label> <input name='email' type='text' id='email' value='<?php echo $_POST['email']; ?>' size='32' class='email' /> <?php echo $errors[2]; ?></div> <div><label>Tu empresa</label> <input name='empresa' type='text' id='empresa' value="<?php echo $_POST['empresa']; ?>" size='32' class='empresa' /> <?php echo $errors[3]; ?></div> <div><label>Tu teléfono</label> <input name='telefono' type="text" id='telefono' value="<?php echo $_POST['telefono']; ?>" size='32' class='telefono' /> <?php echo $errors[4]; ?></div> <div> <label>Mensaje</label> <textarea name='coment' rows='6' id='coment' class="coment"><?php echo $_POST['mensaje']; ?></textarea> <?php echo $errors[5]; ?></div> <div><input name='submit' type='submit' class='button' id='submit' value='Envia Mensaje'></div> <?php echo $result; ?> </form> </div> Link to comment Share on other sites More sharing options...
RALCN Posted December 21, 2012 Report Share Posted December 21, 2012 Creo que está bien. Si le quieres meter algo más, hazlo con jquery, para validar los campos antes del envió del formulario, con eso, podrías perfectamente mostrar los mensajes, sin tener tanto código. Link to comment Share on other sites More sharing options...
chuck Posted January 5, 2013 Report Share Posted January 5, 2013 Creo que está bien. Si le quieres meter algo más, hazlo con jquery, para validar los campos antes del envió del formulario, con eso, podrías perfectamente mostrar los mensajes, sin tener tanto código. Tambien creo que jQuery es la opcion... valida los campos en el cliente, y envias con serialize y jQuery/ajax. No es un formulario de registro asi que encuentro que es innecesaria la validacion en php. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now