Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/03/2011, 08:02
tonysanrusso
 
Fecha de Ingreso: mayo-2010
Mensajes: 84
Antigüedad: 14 años
Puntos: 6
Problema al querer enviar email con archivo adjunto

Buenas a todos,

El problema que tengo es al querer enviar un mail con un archivo adjunto *.txt con la función mail().
He estado averiguando en muchos sitios, he cogido los ejemplos y no he logrado hacerlo y quisiera saber dónde estoy fallando.
Un correo con un Content-Type: text/html lo envio correctamente, no me da problemas.
El inconveniente es al querer enviar un correo Content-Type: multipart/mixed (html con un adjunto).

El código php es el siguiente:

Código PHP:
            $filename getcwd() . "/docs/peluqueria.txt";
            
$fh fopen($filename"r");
            
$filecont fread($fhfilesize($filename));
            
fclose($fh);
            
$fileencode chunk_split(base64_encode($filecont));

            
//ini_set("SMTP", "smtpout.secureserver.net");
            
$recepient "[email protected]";
            
$subject "Tienes un nuevo mensaje de CCDIMAGEN";      
            
$header "From: [email protected]\n";
            
$header .= "MIME-Version: 1.0\n";
            
$header .= "Content-Type: multipart/mixed; boundary=\"--separator--\"\n\n";
            
            
$body "--separator--\n";
            
$body .= "Content-Type: text/html; charset=us-ascii\n";
            
$body .= "Content-Transfer-Encoding: 7bit\n";
            
$body .= "
            <html>
            <h1>Tienes una nueva consulta de: </h1>
            <p><b>Nombre :</b> $name</p>
            <p><b>Email :</b> $email</p>
            <p><b>Mensaje :</b> $message</p>            
            </html>"
;
            
$body .= "\n\n--separator--\n";
            
$body .= "Content-Type: octet-stream; name=\"peluqueria.txt\"\n";
            
$body .= "Content-Disposition: attachment; filename=\"peluqueria.txt\"\n";
            
$body .= "Content-Transfer-Encoding: base64\n";
            
$body .= $fileencode;
            
$body .= "\n\n--separator--\n";
     

            if(
mail($recepient$subject$body$header))
               echo 
"Se envio email correctamente  ";
            else
               echo 
"No se envio el mail";
            
//header("Location: index.html"); 

Y el resultado es:

--separator--
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html><h1>Tienes una nueva consulta de: </h1><p><b>Nombre :</b> prueba</p><p><b>Email :</b> [email protected]</p><p><b>Mensaje :</b> Hola</p> </html>

--separator--
Content-Type: octet-stream; name="peluqueria.txt"Content-Disposition: attachment; filename="peluqueria.txt"Content-Transfer-Encoding: base64

77u/Q29ydGUNCk9uZHVsYWNpb25lcywgTGFjZWFkb3MNClRpbnRlcy wgTWVjaGFzLCBJbHVtaW5hY2nDs24NCkV4dGVuc2lvbmVzIGRl IENhYmVsbG8NClRyYXRhbWllbnRvcyBDYXBpbGFyZXMNCk1hbm ljdXJlIHkgUGVkaWN1cmUsIFNpbXBsZSwgY29uIERpc2XDsW8s IFBhcmFmaW5hIG8gU3BhDQpFeHRyYWNjacOzbiBkZSB1w7Flcm 9zDQpQZXN0YcOxYXMgMSB4IDENCkRlcGlsYWNpw7NuDQpVw7Fh cyBkZSBnZWwsIEFjcmlnZWwNCkxhY2VhZG8gYnJhc2lsZXJv

--separator--

----separator----

A ver si alguien puede darme alguna explicación por favor, gracias.