Código HTML:
<html>
<head>
<script language="javascript" type="text/javascript">
function validar(objFormulario)
{
if (objFormulario.elements["Empresa"].value != "")
{
if (objFormulario.elements["Nombre"].value != "")
{
if (objFormulario.elements["Apellidos"].value != "")
{
if (objFormulario.elements["E-mail"].value != "")
{
if (objFormulario.elements["Consulta"].value != "")
{
if (objFormulario.elements["tlf"].value != "")
{
alert ("Su consulta se ha enviado con exito");
if (!isNaN(parseInt(objFormulario.elements["tlf"].value)))
{
return(true);
}
else
{
alert ("Formato incorrecto en el campo TELÉFONO");
return(false);
}
}
else
{
alert ("Rellene el campo TElËFONO");
return(false);
}
}
else
{
alert ("Haga su consulta");
return(false);
}
}
else
{
alert ("Rellene el campo E-mail");
return(false);
}
}
else
{
alert ("Rellene el campo Apellidos");
return(false);
}
}
else
{
alert ("Rellene el campo Nombre");
return(false);
}
}
else
{
alert ("Rellene el campo Empresa");
return(false);
}
}
</script>
<style type="text/css">
<!--
.Estilo1 {font-size: 24px}
-->
</style>
</head>
<body>
<form name="formulario" action="Formulariotest1.php" method="post" onSubmit="return(validar(this))">
<table width="200" border="0" align="center">
<tr>
<td><span class="Estilo16">Empresa</span></td>
<td><span class="Estilo18">
<label>
<input name="Empresa" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td><span class="Estilo16">Nombre</span></td>
<td><span class="Estilo18">
<label>
<input name="Nombre" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td><span class="Estilo16">Apellidos</span></td>
<td><span class="Estilo18">
<label>
<input name="Apellidos" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td><span class="Estilo16">E-mail</span></td>
<td><span class="Estilo18">
<label>
<input name="E-mail" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td colspan="2" align="center"><span class="Estilo16">Consulta
<label></label>
</span> <span class="Estilo18">
<label></label>
</span></td>
</tr>
</table>
<table width="217" border="0" align="center">
<tr>
<td><label>
<textarea name="Consulta" cols="40" rows="6" wrap="hard"></textarea>
</label></td>
</tr>
</table>
<table width="217
" border="0" align="center">
<tr>
<td><label>
<div align="center">
<input type="submit" name="Submit" value="Enviar">
</div>
</label></td>
<td><label>
<div align="center">
<input type="reset" name="Submit2" value="Borrar">
</div>
</label></td>
</tr>
</table>
</form>
<p>
<?
if ($_POST['Submit']=="Enviar")
{
$Empresa1= $_POST["Empresa"];
$cuerpo = "Formulario enviado\n";
$cuerpo .= "Empresa: ".$_POST["Empresa"]. "\r\n";
$cuerpo .= "Nombre: " . $_POST["Nombre"] . "\r\n";
$cuerpo .= "Apellidos: ". $_POST["Apellidos"]. "\r\n";
$cuerpo .= "Email: " . $_POST["E-mail"] . "\r\n";
$cuerpo .= "Consulta: " ."\r\n". $_POST["Consulta"] . "\r\n";
$res=mail("[email protected]","Consulta desde Internet de ".$Empresa1,$cuerpo) or die ("Hubo un error");
if ($res)
echo "<script type='text/javascript'> alert('Su consulta se ha enviado con exito') </script>";
else
echo "<br><br><p align='center'><b>Problema al enviar el Mensaje.</b></p>";
}
?>
</p>
</body>
</html>