Foros del Web » Programando para Internet » PHP »

Enviar mensajes a correo con PHP

Estas en el tema de Enviar mensajes a correo con PHP en el foro de PHP en Foros del Web. Hola siempre he deseado mandar mensajes desde mi pagina por ejemplo www.mipagina.com/contactos.html a una cuenta de correo como por ejemplo [email protected] y no he logrado ...
  #1 (permalink)  
Antiguo 14/10/2008, 16:31
Avatar de salvador86  
Fecha de Ingreso: enero-2008
Ubicación: Guadalajara- Mexico
Mensajes: 467
Antigüedad: 16 años, 4 meses
Puntos: 2
Enviar mensajes a correo con PHP

Hola siempre he deseado mandar mensajes desde mi pagina por ejemplo www.mipagina.com/contactos.html a una cuenta de correo como por ejemplo [email protected] y no he logrado del todo hacerlo. tengo este codigo en php que parece resultar pero, no logro que funcione espero me puedan ayudar, estoy en cero en php.

Cita:
<?
$correo = $_POST['correo'];
$nombre = $_POST['nom'];

$cuerpo = "Mensaje desde la página \n";
$cuerpo .= "Nombre: " . $HTTP_POST_VARS["nom"] . "\n";
$cuerpo .= "Apellidos: " . $HTTP_POST_VARS["ape"] . "\n";
$cuerpo .= "Telefono: " . $HTTP_POST_VARS["telf"] . "\n";
$cuerpo .= "Correo: " . $HTTP_POST_VARS["correo"] . "\n";
$cuerpo .= "Comentarios: " . $HTTP_POST_VARS["com"] . "\n";

$headers = "From: $correo";

mail("[email protected]","Mensaje recibido desde la pagina web",$cuerpo,$headers);
echo "<p>correcto</p>";
echo "<meta HTTP-EQUIV='refresh' content='5;url=http://www.mipagina.com/gracias.html'>";

?>
y mi formulario seria el siguiente:
Cita:
<form action="zzzenvcorreo.php" method="post" name="dq" id="dq">
<div class="cesta">
<div id="cont-solicitud">
<table width="456" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="172" height="22">Nombres</th>
<th width="284"><input name="nom" type="text" class="formulario" id="nom" size="50">
*</th>
</tr>
<tr>
<th height="22">Apellidos</th>
<th><input name="ape" type="text" class="formulario" id="ape" size="50" />
*</th>
</tr>
<tr>
<th height="22">Tel&eacute;fono</th>
<th ><input name="telf" type="text" class="formulario" id="telf" size="50"></th>
</tr>
<tr>
<th height="22">E-mail</th>
<th ><input name="correo" type="text" class="formulario" id="correo" value="" size="50" />
*</th>
</tr>
<tr>
<th height="22">Sexo</th>
<th class="sttextazul6">M&nbsp;<input type="radio" checked name="Sexo" value="Masculino">
&nbsp;F&nbsp;<input type="radio" name="Sexo" value="Femenino"></th>
</tr>
<tr>
<th valign="top">Sugerencias o Comentarios</th>
<th ><textarea name="com" cols="44" rows="6" class="formulario" id="com"></textarea> </th>
</tr>
<tr>
<th valign="top"><input name="Submit" type="submit" onclick="YY_checkform('dq','nom','#q','0','Campo nombre','ape','#q','0','Campo apellido','telf','#000000000_999999999','1','Campo teléfono','correo','#S','2','Campo correo');return document.MM_returnValue" value="Enviar" /></th>
<th ><input name="Submit2" type="reset" onclick="validate();return returnVal;" value="Borrar" id="Submit2" /></th>
</tr>
</table>
</div>
</div>
</form>
Aquí tengo una funcion que valida el formulario que lo coloco entre las etiquetas HEAD
Cita:
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=fal se,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidd en'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#");at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.g etMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a[i].match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]]:o;
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1& &o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('Veririfar lo siguiente:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
Como no veo en el php el nombre de dominio de la web, tan solo veo el correo a donde quiero que llegue los correos, creo que debe haber mas que hacer lo subi a un servidor (no gratuito, tengo un servidor pagado) y no me llegua a mi correo de gmail.

Espero que me puedan ayudar casi de cero, pues he probado muchos códigos pero ninguna me resulta. Gracias
  #2 (permalink)  
Antiguo 14/10/2008, 17:48
Avatar de Carxl
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: Bogotá
Mensajes: 2.993
Antigüedad: 17 años, 9 meses
Puntos: 70
Respuesta: Enviar mensajes a correo con PHP

Nada como la clase phpmailer para tal fin

Intenta con ella, te irá bien

Saludos
__________________
Hay 10 tipos de personas, los que entienden binario y los que no. (Anónimo)
www.programandoweb.com
  #3 (permalink)  
Antiguo 14/10/2008, 17:53
 
Fecha de Ingreso: mayo-2005
Ubicación: Cancun
Mensajes: 35
Antigüedad: 19 años
Puntos: 0
Respuesta: Enviar mensajes a correo con PHP

$namep = $_POST['nombre'] ;
$cargo= $_POST['cargo'];
$companyp= $_POST['empresa'];
$emailp = $_POST['email'];
$phonep = $_POST['telefono'];
$directionp = $_POST['direccion'];
$subjectp = $_POST['asunto'];
$commentp = $_POST['cuerpo'];
$error = $_POST['error'];


$name = 'Nombre: ' . $namep. '<br>';
$cargo = 'Cargo:' . $cargo .'<br>';
$company = 'Empresa:' . $companyp .'<br>';
$email = 'Email: ' . $emailp . '<br>';
$phone = 'Telefono: ' . $phonep . '<br>';
$direction = 'Dirección: '. $directionp . '<br>';
$msg_subject = 'Titulo del mensaje: ' . $subjectp . '<br>';
$coment = 'Cuerpo del mensaje: ' . $commentp . '<br>';
$message = mysql_escape_string($name . $cargo .$email . $company .$phone. $direction . $msg_subject . $coment);
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: " .$namep. "<".$emailp.">" ;
mail('[email protected]', 'Contacto desde | dominio | Web Site', $message, $headers);
session_destroy();
header ("Location: index.php");
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 18:18.