25/08/2004, 14:06
|
| | | Fecha de Ingreso: junio-2004
Mensajes: 193
Antigüedad: 19 años, 10 meses Puntos: 1 | |
El Ejemplo es de un formulario de contacto, alguien le pude hechar una revizada para ver si esta bien efectuado Código PHP: <? if(!isset($_POST["Submit"])){ ?> <link href="../login6/dd.css" rel="stylesheet" type="text/css"> <form name="form1" method="post" action="contacto.php"> <div align="center"> <table width="51%" border="0" cellspacing="2"> <tr> <td class="unnamed1CopiaCopia"><div align="center">Formulario de Contacto</div></td> </tr> <tr> <td height="21"> </td> </tr> </table> </div> <div align="center"> <table width="51%" border="0" cellspacing="2" class="unnamed1CopiaCopia"> <tr> <td width="40%" valign="top"> <div align="right">Nombre:</div></td> <td width="60%"><input name="nombre" type="text" id="nombre"></td> </tr> <tr> <td valign="top"> <div align="right">Email:</div></td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td valign="top"> <div align="right">Sitio Web:</div></td> <td><input name="sitioweb" type="text" id="sitioweb"></td> </tr> <tr> <td valign="top"> <div align="right">Pais:</div></td> <td><input name="pais" type="text" id="pais"></td> </tr> <tr> <td valign="top"> <div align="right">Asunto:</div></td> <td><select name="asunto" id="asunto"> <option>Pregunta</option> <option>Reclamo</option> <option>Felicitaciones</option> <option>Reporte de Errores</option> <option>Webmaster</option> </select></td> </tr> <tr> <td valign="top"> <div align="right">Mensaje:</div></td> <td><textarea name="mensaje" cols="25" rows="5" id="mensaje"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Enviar"> <input type="reset" name="Submit2" value="Borrar"></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </div> </form> <? }else{ $campos=array("nombre","email","sitioweb","pais","mensaje"); $faltan=valida($campos); foreach($faltan as $campo){ echo "error falta el campo :".$campo."<br>"; } if(!isset($campo)){ if(!eregi("^([a-zA-Z0-9]+)@([a-zA-Z0-9]+)(\.[a-zA-Z0-9]{2,3})$",$_POST["email"])){ echo "email no valido"; }elseif(!eregi("^(ht{2}p://w{3})(\.[a-zA-Z0-9]+)+(\.[a-zA-Z0-9]{2,3})$",$_POST["sitioweb"])){ echo 'Url Mal Escrita: debe poner como en el ejemplo (http://)'; }elseif(preg_match("/(\<|\>)/",$_POST["mensaje"])){ echo "no valido"; }else{ $nombre=stripslashes($_POST["nombre"]); $email=stripslashes($_POST["email"]); $sitioweb=stripslashes($_POST["sitioweb"]); $pais=stripslashes($_POST["pais"]); $asunto=stripslashes($_POST["asunto"]); $mensaje=stripslashes($_POST["mensaje"]); $email=enviaemail($nombre,$email,$sitioweb,$pais,$asunto,$mensaje); if($email){ header("location:gracias.php"); exit; }else{ header("location:error.php"); exit; } } } } ?> <? function valida($campos){ $faltan=array(); foreach($campos as $campo){ if(empty($_POST[$campo])){ $faltan[]=$campo; } } return $faltan; } ?> <? function enviaemail($nombre,$email,$sitioweb,$pais,$asunto,$mensaje){ $para="[email protected]"; $de=$email; $respuesta=$email; $asunto=$asunto; $mensaje="<b>Nombre:</b>$nombre<br><b>Pais:</b>$pais<br><b>Sitio Web</b>&sitioweb<br><b>Mensaje :</b> $mensaje"; $cabecera="Mime-Version: 1.0\r\n"; $cabecera.="Content-Type: text/html; charset:iso-8859-1\r\n"; $cabecera.="To:$para\r\n"; $cabecera.="From:$de\r\n"; $cabecera.="Reply-To:$respuesta\r\n"; $cabecera.="X-Mailer: PHP/".phpversion()."\r\n"; $email=mail($para,$asunto,$mensaje,$cabecera); return($email); } ?>
Última edición por don_fransisco; 25/08/2004 a las 14:07 |