
formulario.php
- <!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">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <meta name="author" content="joason.com">
- <title>Formulario de contacto</title>
- <script language="JavaScript">
- function formulariodecontacto(){
- if (document.formulario.nombre.value==""){
- alert("Por favor ingresa tu Nombre.");
- document.formulario.nombre.select();
- return false;
- }
- if (document.formulario.correo.value==""){
- alert("Por favor ingresa tu E-mail.");
- document.formulario.correo.select();
- return false;
- }
- if (revisar_correo(document.formulario.correo.value)==false){
- alert("Por favor ingresa un E-mail valido.");
- document.formulario.correo.select();
- return false;
- }
- if (document.formulario.asunto.value==""){
- alert("Por favor ingresa un asunto.");
- document.formulario.asunto.select();
- return false;
- }
- if (document.formulario.mensaje.value==""){
- alert("Por favor ingresa un mensaje.");
- document.formulario.mensaje.select();
- return false;
- }
- return true;
- }
- function revisar_correo(str){
- var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
- if (filter.test(str)){ return true; }else{ return false; }
- }
- </script>
- </head>
- <body>
- <div style="margin:auto; width: 310px;">
- <br />
- <form action="enviar.php" method="post" name="formulario" onSubmit="return formulariodecontacto()">
- Su Nombre:<br />
- <input name="nombre" type="text" class="campo" id="nombre" size="50" /><br /><br />
- Su e-mail:<br />
- <input name="correo" type="text" class="campo" id="correo" size="50" /><br /><br />
- Asunto:<br />
- <input name="asunto" type="text" class="campo" id="asunto" size="50" /><br /><br />
- Mensaje:<br />
- <textarea name="mensaje" cols="40" rows="5" class="campo" id="mensaje" />
- <input class="boton" name="Submit" type="submit" value=" Envíar Mensaje " />
- </form>
- </div>
- </body></html>
enviar.php
- <?php
- // declaramos el destinatario
- $destino = "Aqí nuestra dirección de E-mail";
- // Cargando las variables desde el formulario
- $asunto = $_POST["asunto"];
- $mensaje = $_POST["mensaje"];
- $nombre = $_POST["nombre"];
- $correo = $_POST["correo"];
- // Cuerpo del mensaje :
- $body ="Tienes un nuevo mensaje de $nombre:
- E-Mail : $correo
- Asunto : $asunto
- Mensaje : $mensaje";
- // Si todo está correcto enviamos el correo
- mail($destino, $asunto, $body , "From: $nombre <$correo>");
- ?>
- <!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">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <meta name="author" content="joason.com">
- <title>Correo evíado</title>
- <meta http-equiv="refresh" content="3; url=formulario.php">
- </head>
- <body>
- <center>
- Gracias, Su correo ha sido enviado.</center>
- </body></html>

Espero que os sea de utilidad.
Saludos..