Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/07/2009, 14:21
Avatar de canzoneta
canzoneta
 
Fecha de Ingreso: diciembre-2003
Ubicación: Mendoza
Mensajes: 79
Antigüedad: 21 años, 1 mes
Puntos: 1
Respuesta: Envio a mail con php

Yo te puedo ofrecer éste, que valida los campos incompletos o incorrectos y está todo en el mismo archivo.

Ojalá te sea útil.

Código 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" />
<style>
body {font-family:Verdana, Arial, Helvetica, sans-serif}
.error {color:#FF0000; font-size:10px}
.gracias {text-align:center}
</style>
<title>Contacto</title>
</head>

<body>
  <?php 

    $nombre 
"";
    
$edad "";
    
$email "";
    
$mensaje "";
    
if(isset(
$_POST['submit'])) 
{
    
$to "[email protected]"// Cambiar por tu correo.
    
$subject "Asunto"// Cambiar por el asunto de tu preferencia.
    
$nombre trim($_POST['nombre']);
    
$edad trim($_POST['edad']);
    
$email trim($_POST['email']);
    
$mensaje trim($_POST['mensaje']);
    
$cabeceras "From: ".$name." <".$email.">";

    
    
       if(  (!empty(
$nombre)) && (!empty($edad) && is_numeric($edad)) && (eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}"$email)) && (!empty($mensaje) ) ) 
           { 
               
$body "Nombre: $name\n Edad: $edad\n E-Mail: $email\n Mensaje:\n\n $mensaje";

            echo 
"<div class=\"gracias\"><br /><br />Gracias <b>$nombre</b><br /><br /> Tus datos han sido enviados correctamenete.<br /><br /> Uno de nuestros representantes se pondr&aacute; en contacto contigo a la brevedad.</div>"// Cambiar por la frase de agradecimiento de tu preferencia.
            
mail($to$subject$body$cabeceras);
            exit;
   
    } else { 

      echo 
"<p>Por favor completa todos los campos.</p>"
      if(empty(
$nombre)) 
         
$nonombre "Por favor escribe tu nombre."
      if(empty(
$edad) || !is_numeric($edad)) 
         
$noedad "Por favor escribe tu edad."
      if(!
eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}"$email)) 
         
$noemail "Por favor escribe tu e-mail."
      if(empty(
$mensaje)) 
         
$nomsje "Por favor escrube un mensaje.";
      echo 
"<br>"
    } 
}

?>
<form method="POST" action="<?php echo $SERVER['PHP_SELF']; ?>">
    <table width="100%" border="0" cellpadding="5">
      <tr>
        <td width="20%" align="left" valign="top">Nombre:</td>
        <td align="left">
          <input name="nombre" type="text" id="nombre" value="<?php echo $nombre?>" size="30"><div class="error"><?php echo $nonombre?></div>        </td>
      </tr>
      <tr>
        <td width="20%" align="left" valign="top">Edad:</td>
        <td align="left">
          <input name="edad" type="text" id="edad" value="<?php echo $edad?>" size="4" maxlength="3"><div class="error"><?php echo $noedad?></div>        </td>
      </tr>
      <tr>
        <td width="20%" align="left" valign="top">E-mail:</td>
        <td align="left">
          <input name="email" type="text" value="<?php echo $email?>" size="30"><div class="error"><?php echo $noemail?></div>        </td>
      </tr>
      <tr>
        <td width="20%" align="left" valign="top">Mensaje:</td>
        <td align="left"><textarea name="mensaje" id="mensaje" cols="45" rows="5"><?php echo $mensaje?></textarea><div class="error"><?php echo $nomsje?></div>        </td>
      </tr>
  </table>

  <input type="submit" value="Enviar" name="submit">

</form>

</body>
</html>