Foros del Web » Programando para Internet » PHP »

mails tipo html

Estas en el tema de mails tipo html en el foro de PHP en Foros del Web. ok, funciona muy bien cuando se lo mando a alguien que tenga una cuenta hotmail, no? pero se chiufla todo cuando lo mando a una ...
  #1 (permalink)  
Antiguo 19/04/2004, 12:29
Avatar de numbloq  
Fecha de Ingreso: marzo-2004
Ubicación: Capital Federal
Mensajes: 124
Antigüedad: 20 años, 1 mes
Puntos: 0
mails tipo html

ok, funciona muy bien cuando se lo mando a alguien que tenga una cuenta hotmail, no? pero se chiufla todo cuando lo mando a una cuenta personal que la abre con el outlook...
esto es lo que estoy haciendo
Código PHP:
 $para="[email protected]"
 
$sheader="From:"."[email protected]"."\nReply-To:"."[email protected]"."\n";   
 
$sheader=$sheader."X-Mailer:PHP/".phpversion()."\n";    
$sheader=$sheader."Mime-Version: 1.0\n";    
$sheader=$sheader."Content-Type: text/html";    
mail("$para","hola","".$emilio."","[email protected]",$sheader); 
alguien conoce la solucion a mi problema?
gracias.

Última edición por numbloq; 19/04/2004 a las 12:55
  #2 (permalink)  
Antiguo 19/04/2004, 13:14
Ex Colaborador
 
Fecha de Ingreso: junio-2002
Mensajes: 9.091
Antigüedad: 21 años, 10 meses
Puntos: 16
Hola,

Revisa en el manual www.php.net/mail los parametros de la funcion mail() y su significado.

Saludos.
__________________
Josemi

Aprendiz de mucho, maestro de poco.
  #3 (permalink)  
Antiguo 19/04/2004, 13:58
Avatar de numbloq  
Fecha de Ingreso: marzo-2004
Ubicación: Capital Federal
Mensajes: 124
Antigüedad: 20 años, 1 mes
Puntos: 0
la respuesta para los que la quieran es esta,
I noticed when sending html mail to ms outlook 2000 outlook will not interpret correctally the headers unless you place a space between the \r\n appending the header line so that it looks like:

$header = "From: somebody <[email protected]>\r \n";

This seems to work in all other email clients I have tried it on so far (Mozilla, TWIG) without breaking them. Trust M$ to use screwy headers. The behavior I recieved out of outlook was that the first header was recognized as a header and all other headers after that one were placed in the body of the message.

Jeff
Si no sabes ingles en altavista.com hay un lindo traductor...
__________________
que el erlenmeyer carezca de tapa no es un problema que me aconte
  #4 (permalink)  
Antiguo 19/04/2004, 14:31
Avatar de numbloq  
Fecha de Ingreso: marzo-2004
Ubicación: Capital Federal
Mensajes: 124
Antigüedad: 20 años, 1 mes
Puntos: 0
Despues de probar un par de cosas he decidido usar esto que es mejor...
Código PHP:
/*
This might be some useful stuff to send out emails in either text
or html or multipart version, and attach one or more files or even
none to it. Inspired by Kieran's msg above, I thought it might be 
useful to have a complete function for doing this, so it can be used 
wherever it's needed. Anyway I am not too sure how this script will
behave under Windows.

{br} represent the HTML-tag for line break and should be replaced,
but I did not know how to not get the original tag  parsed here.

function SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles)
$From      ... sender mail address like "[email protected]"
$FromName  ... sender name like "My Name"
$To        ... recipient mail address like "[email protected]"
$ToName    ... recipients name like "Your Name"
$Subject  ... subject of the mail like "This is my first testmail"
$Text      ... text version of the mail
$Html      ... html version of the mail
$AttmFiles ... array containing the filenames to attach like array("file1","file2")
*/

$TEXT="This is the first test\n in text format\n.";
$HTML="<font color=red>This is the first test in html format.</font>";
$ATTM=array("/home/myself/test/go.jpg",
           
"/home/myself/test/SomeDoc.pdf");

SendMail(
   
"[email protected]","PHP Apache Webmailer",        //sender
   
"[email protected]","Recipients Name",    //recipient
   
"Testmail",                              //subject
   
$TEXT,$HTML,$ATTM);                      //body and attachment(s)
   
function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles){
 
$OB="----=_OuterBoundary_000";
 
$IB="----=_InnerBoundery_001";
 
$Html=$Html?$Html:preg_replace("/\n/","{br}",$Text
  or die(
"neither text nor html part present.");
 
$Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail.";
 
$From or die("sender address missing");
 
$To or die("recipient address missing");
   
 
$headers ="MIME-Version: 1.0\r\n"
 
$headers.="From: ".$FromName." <".$From.">\n"
 
$headers.="To: ".$ToName." <".$To.">\n"
 
$headers.="Reply-To: ".$FromName." <".$From.">\n"
 
$headers.="X-Priority: 1\n"
 
$headers.="X-MSMail-Priority: High\n"
 
$headers.="X-Mailer: My PHP Mailer\n"
 
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";

 
//Messages start with text/html alternatives in OB
 
$Msg ="This is a multi-part message in MIME format.\n";
 
$Msg.="\n--".$OB."\n";
 
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";

 
//plaintext section 
 
$Msg.="\n--".$IB."\n";
 
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
 
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
 
// plaintext goes here
 
$Msg.=$Text."\n\n";

 
// html section 
 
$Msg.="\n--".$IB."\n";
 
$Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
 
$Msg.="Content-Transfer-Encoding: base64\n\n";
 
// html goes here 
 
$Msg.=chunk_split(base64_encode($Html))."\n\n";

 
// end of IB
 
$Msg.="\n--".$IB."--\n";

 
// attachments
 
if($AttmFiles){
  foreach(
$AttmFiles as $AttmFile){
   
$patharray explode ("/"$AttmFile); 
   
$FileName=$patharray[count($patharray)-1];
   
$Msg.= "\n--".$OB."\n";
   
$Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n";
   
$Msg.="Content-Transfer-Encoding: base64\n";
   
$Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";
           
   
//file goes here
   
$fd=fopen ($AttmFile"r");
   
$FileContent=fread($fd,filesize($AttmFile));
   
fclose ($fd);
   
$FileContent=chunk_split(base64_encode($FileContent));
   
$Msg.=$FileContent;
   
$Msg.="\n\n";
  }
 }
   
 
//message ends
 
$Msg.="\n--".$OB."--\n";
 
mail($To,$Subject,$Msg,$headers);    
 
//syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");

__________________
que el erlenmeyer carezca de tapa no es un problema que me aconte
  #5 (permalink)  
Antiguo 19/04/2004, 14:57
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues ya puestos .. yo recomiendo la classe:

PHP mailer
http://phpmailer.sourceforge.net

que implementa en sus cabeceras HTTP casi todo el protocolo SMTP y brinda de forma cómoda funcionalidades extra a mail() de PHP original como la de enviar archivos adjuntos entre otras cosas de forma "compacta" (es una classe) y facil de usar.

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
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 03:31.