Foros del Web » Programando para Internet » PHP »

Envio a mail con php

Estas en el tema de Envio a mail con php en el foro de PHP en Foros del Web. Hola comunidad, eh realizado el siguiente formulario en html y estoy buscando algun codigo php para poder enviarlo a mi mail: Código HTML: <form id= ...
  #1 (permalink)  
Antiguo 01/07/2009, 12:41
Avatar de eMaa  
Fecha de Ingreso: octubre-2008
Mensajes: 223
Antigüedad: 15 años, 6 meses
Puntos: 1
Envio a mail con php

Hola comunidad, eh realizado el siguiente formulario en html y estoy buscando algun codigo php para poder enviarlo a mi mail:

Código HTML:
<form id="form1" name="form1" method="post" action="send.php">
            <label><span class="Estilo6"><br />
            Nombre</span>
              <input name="textfield" type="text" size="20" maxlength="30" />
            </label>
            <p>&nbsp;</p>
            <p>
              <label><span class="Estilo6">Edad
              </span>
              <input name="textfield2" type="text" size="10" maxlength="2" />
              </label>
            </p>
            <p>&nbsp;</p>
            <p>
              <label><span class="Estilo6">E-Mail
              </span>
              <input name="textfield3" type="text" size="20" />
              </label>
            </p>
            <p>&nbsp;</p>
            <p>
              <label><span class="Estilo6">Mensaje</span>
              <textarea name="textarea" cols="50" rows="5"></textarea>
              </label>
            </p>
            <p>
              <label>
              <input type="submit" name="Submit" value="Enviar" />
              </label>
            </p>
            <p>&nbsp;</p>
          </form> 
desde ya muchas gracias por haber leido
  #2 (permalink)  
Antiguo 01/07/2009, 13:09
 
Fecha de Ingreso: enero-2009
Mensajes: 100
Antigüedad: 15 años, 4 meses
Puntos: 1
Respuesta: Envio a mail con php

Este es un codigo mio:

Código PHP:
<?php
function form_correo($error)
{

echo 
'

<!-- INICIO Form correo -->

<table border="0" style="float: right" cellpadding="0" cellspacing="0" width="78%">'
;

if(
$error == "1")
    {
    
error_correo();
    }
elseif(
$error == "0")
    {
    
bien_correo();
    }
elseif(
$error == "")
    {
    echo 
'<br>';
    }

echo 
'
    <form action="tupagina.php" method="post">
    <table class="tborder" border="0" align="center" cellpadding="6" cellspacing="1" width="auto">

    <tr>
        <td class="titulo" colspan="2" align="center">Enviar Correo</td>
    </tr>
    
    <td class="panelsurround" align="center">
            <div class="panel">
                <table align="center" border="0" cellpadding="6" cellspacing="1" width="100%">

                    <tr>
                        <td><label for="de" class="fuentesmall">De: </label></td>
                        <td><input class="textbox" type="text" name="de" id="de" size="33"><input type="hidden" name="pase" value="si"></td>
                    </tr>

                    <tr>
                        <td><label for="para" class="fuentesmall">Para: </td>
                        <td><input class="textbox" type="text" name="para" id="para" size="33"></td>
                    </tr>

                    <tr>
                        <td><label for="responderA" class="fuentesmall">Responder A: </label></td>
                        <td><input class="textbox" type="text" name="responderA" id="responderA" size="33"></td>
                    </tr>

                    <tr>
                        <td><label for="asunto" class="fuentesmall">Asunto: </label></td>
                        <td><input class="textbox" type="text" name="asunto" id="asunto" size="33"></td>
                    </tr>
                    
                    <tr>
                        <td><label for="mensaje" class="fuentesmall">Mensaje: </label></td>
                        <td><textarea class="textbox" name="mensaje" id="mensaje" cols="31" rows="6"></textarea></td>
                    </tr>

                    <tr>
                        <td align="center" colspan="2"><input class="boton" type="submit" value="Enviar Correo"></td>
                    </tr>

                </table>
            </div>
        </td>
        
    </table>
    </form>
    
</table>

<!-- FIN Form correo -->

'
;
}

function 
error_correo()
{
echo 
'

<!-- INICIO Form correo ERROR -->

<table class="tborder" border="0" align="center" cellpadding="5" cellspacing="1" width="auto">

    <td align="center" class="titulo">
        Error, Posibles Causas
    </td>
    
    <tr>
        <td align="center" class="panel">
            <span class="fuentesmall_error">
                Debes rellenar todos los campos.
            </span>
        </td>
    </tr>

</table>

<br>

<!-- FIN Form correo ERROR -->

'
;
}

function 
bien_correo()
{
echo 
'

<!-- INICIO Form correo BIEN -->

<table class="tborder" border="0" align="center" cellpadding="5" cellspacing="1" width="auto">
    
    <td align="center" class="titulo">
        Correcto
    </td>
    
    <tr>
        <td align="center" class="panel">
            <span class="fuentesmall_bien">
                Mensaje enviado correctamente.
            </span>
        </td>
    </tr>

</table>

<br>

<!-- FIN Form correo ERROR -->

'
;
}

session_start();
if(
$_SESSION['usuario'] != "")
    {
    if(
$_POST['pase'] == "si")
        {
        
$para      $_POST['para'];
        
$asunto    $_POST['asunto'];
        
$mensaje   $_POST['mensaje'];
        
$de        $_POST['de'];
        
$responderA$_POST['responderA'];
        
$cabeceras 'From: '.$de."\r\n".
        
'Reply-To: '.$responderA;
        if(empty(
$para))
            {
            
$para="";
            }
        if(empty(
$para))
            {
            
$asunto="";
            }
        if(empty(
$para))
            {
            
$mensaje="";
            }
        if(empty(
$para))
            {
            
$de="";
            }
        if(empty(
$para))
            {
            
$responderA="";
            }
            
        if((
$para != "")and($asunto != "")and($mensaje != "")and($de != "")and($responderA != ""))
            {
            
mail($para$asunto$mensaje$cabeceras) or die ("Error: Mensaje no enviado");
            
form_correo("0");
            }
        else
            {
            
form_correo("1");
            }
        }
    else
        {
        
form_correo("");
        }
    }
?>
Funciona a la perfeccion!!!

Espero te ayude!!!
  #3 (permalink)  
Antiguo 01/07/2009, 13:40
Avatar de eMaa  
Fecha de Ingreso: octubre-2008
Mensajes: 223
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Envio a mail con php

Hola, muchas gracias por responder,

yo necesito algo sencillo, no se nada de php :(, me pasaron este que es cortito:

Código PHP:
< ?php
$nombre 
$_POST['nombre'];
$mail $_POST['mail'];
$empresa $_POST['empresa'];

$header 'From: ' $mail " \r\n";
$header .= "X-Mailer: PHP/" phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";

$mensaje "Este mensaje fue enviado por " $nombre ", de la empresa " $empresa " \r\n";
$mensaje .= "Su e-mail es: " $mail " \r\n";
$mensaje .= "Mensaje: " $_POST['mensaje'] . " \r\n";
$mensaje .= "Enviado el " date('d/m/Y'time());

$para 'mi mail';
$asunto 'Contacto desde la web';

mail($para$asuntoutf8_decode($mensaje), $header);

echo 
'&estatus=ok&';

?> 
Los mails me llegan pero sin informacion, es decir que falta los datos que se ingresan en el formulario, sera que no coincide algo?
  #4 (permalink)  
Antiguo 01/07/2009, 14:21
Avatar de canzoneta  
Fecha de Ingreso: diciembre-2003
Ubicación: Mendoza
Mensajes: 79
Antigüedad: 20 años, 4 meses
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>
  #5 (permalink)  
Antiguo 01/07/2009, 16:00
Avatar de eMaa  
Fecha de Ingreso: octubre-2008
Mensajes: 223
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Envio a mail con php

Muchisimas gracias, me re sirvi, siempre me sacan de aputos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:57.