------------------------------------------
<form id="form1" name="form1" method="post" action="contacto.php" onsubmit="return validar(this);">
Nombre :<br />
<input name="nombre" type="text" id="nombre" maxlength="100" />
<br />
Email :<br />
<input name="email" type="text" id="email" maxlength="150" />
<br />
Contenido :<br />
<textarea name="contenido" id="contenido" cols="17" rows="5"></textarea>
<br /><br />
<input type="submit" name="button" id="button" value="Enviar" />
<input type="reset" name="button2" id="button2" value="Restablecer" />
<input name="accion" type="hidden" id="accion" value="enviar" />
</form>
* Segundo crear validador de Email y para evitar espacios en blanco en Javascript :
------------------------------------------------------------------------------------------------
<script type="text/javascript" language="javascript">
function vacio(q) {
for ( i = 0; i < q.length; i++ ) {
if ( q.charAt(i) != " " ) {
return true;
}
}
return false;
}
function validar(F){
if (vacio(F.nombre.value) == false){
alert("Ingrese su NOMBRE en el cuadro de texto.");
F.nombre.focus();
return false;
}
if (vacio(F.email.value) == false){
alert("Ingrese su EMAIL en el cuadro de texto.");
F.email.focus();
return false;
}
var er_email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
if(!er_email.test(F.email.value)) {
alert("Contenido del campo E-MAIL no válido.")
F.email.focus();
return false;
}
return true;
}
</script>
* Tercero crear el proceso de envio del formulario :
---------------------------------------------------------
// PROCESO DE ENVIO DE FORMULARIO DE CONTACTOS, ESTO SE UBICARA
// AL COMIENZO DE LA PAGINA
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$contenido = $_POST['contenido'];
$accion = $_POST['accion'];
if(isset($accion)){
$dest = "miemail@midominio.com"; // EMAIL DE DESTINO
$head = "From: ".$nombre." <".$email."> \r\n";
// Ahora creamos el cuerpo del mensaje
$msje = "Hola esto es una prueba del formulario de contactos \n";
$msje.= "NOMBRE : ".$nombre." \n";
$msje.= "EMAIL : ".$email." \n";
$msje.= "CONTENIDO : ".$contenido."\n";
// Finalmente enviamos el mensaje
if (mail($dest,"NUEVA CONSULTA ENVIADA",$msje, $head))
{
$aviso = "<p align='center' style='color:blue;'><b>Su Consulta ha sido enviada correctamente \n";
$meta = "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=contacto.php'>";
}
else
{
$aviso = "<p align='center' style='color:red;'><b>Error de envío. Vuelva a Intentarlo de Nuevo</b></p>";
$meta = "";
}
}
* Cuarto - Aqui mostrare el codigo completo de como deberia estar :
------------------------------------------------------------------------------
<?
// PROCESO DE ENVIO DE FORMULARIO DE CONTACTOS
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$contenido = $_POST['contenido'];
$accion = $_POST['accion'];
if(isset($accion)){
$dest = "miemail@midominio.com"; // EMAIL DE DESTINO
$head = "From: ".$nombre." <".$email."> \r\n";
// Ahora creamos el cuerpo del mensaje
$msje = "Hola esto es una prueba del formulario de contactos \n";
$msje.= "NOMBRE : ".$nombre." \n";
$msje.= "EMAIL : ".$email." \n";
$msje.= "CONTENIDO : ".$contenido."\n";
// Finalmente enviamos el mensaje
if (mail($dest,"NUEVA CONSULTA ENVIADA",$msje, $head))
{
$aviso = "<p align='center' style='color:blue;'><b>Su Consulta ha sido enviada correctamente \n";
$meta = "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=contacto.php'>";
}
else
{
$aviso = "<p align='center' style='color:red;'><b>Error de envío. Vuelva a Intentarlo de Nuevo</b></p>";
$meta = "";
}
}
?>
<!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=utf-8" />
<?
echo $meta ;
?>
<title>Formulario de Contactos</title>
<script type="text/javascript" language="javascript">
function vacio(q) {
for ( i = 0; i < q.length; i++ ) {
if ( q.charAt(i) != " " ) {
return true;
}
}
return false;
}
function validar(F){
if (vacio(F.nombre.value) == false){
alert("Ingrese su NOMBRE en el cuadro de texto.");
F.nombre.focus();
return false;
}
if (vacio(F.email.value) == false){
alert("Ingrese su EMAIL en el cuadro de texto.");
F.email.focus();
return false;
}
var er_email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
if(!er_email.test(F.email.value)) {
alert("Contenido del campo E-MAIL no válido.")
F.email.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<?
echo $aviso ;
?>
<form id="form1" name="form1" method="post" action="contacto.php" onsubmit="return validar(this);">
Nombre :<br />
<input name="nombre" type="text" id="nombre" maxlength="100" />
<br />
Email :<br />
<input name="email" type="text" id="email" maxlength="150" />
<br />
Contenido :<br />
<textarea name="contenido" id="contenido" cols="17" rows="5"></textarea>
<br /><br />
<input type="submit" name="button" id="button" value="Enviar" />
<input type="reset" name="button2" id="button2" value="Restablecer" />
<input name="accion" type="hidden" id="accion" value="enviar" />
</form>
</body>
</html>
*****************************************************************
Espero le haya sido de util

hotmail.com

Reportar Enlace Roto o Abusos
