Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/06/2013, 18:41
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 1 mes
Puntos: 292
Respuesta: enviar archivo adjunto al mail

Lo primero debes subir el archivo, agregando a tu form:

Cita:
<input type="file" name="file" id="file"><br>
Lo segundo cojer el archivo y enviarlo:

Código PHP:
<?php
if ($_FILES["file"]["error"] == 0){
    
/*  envio  */

    // algo que es improbable aparezca dentro del mensaje y lo delimita:
    
$mail_boundary md5(uniqid(time())); 
    
$mail_headers "MIME-Version: 1.0\r\n";
    
$mail_headers .= "Content-type: multipart/mixed;boundary=\"$mail_boundary \"";
    
$mail_headers .= "\r\n\r\n";
    
$mail_headers .= "This is a multi-part message in MIME format.";

    
$mail_headers .= "\r\n\r\n";

    
$file chunk_split(base64_encode($file));

    
$mail_body "--$mail_boundary\n";
    
$mail_body .= "Content-type: text/plain; charset=euc-kr\r\n";
    
$mail_body .= "Content-transfer-encoding: 8bit\r\n\r\n";
    
$mail_body .= "Enviando archivo bla bla bla\r\n";
    
$mail_body .= "--$mail_boundary\r\n";
    
$filename basename($_FILES['file']['name']);

$mail_body .= "Content-type: application/msword; name=$filename\r\n";
$mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
$mail_body .= $file"\r\n\r\n";

$mail_body .= " --$mail_boundary--";

mail($mail_to$mail_subject$mail_body$mail_headers);
}

Cita:
Multipart messages

La MIME multipart message debe contener un 'boundary' en el "Content-Type: " header; este boundary, el cual no debe repetirse dentro del mensaje MIMI es colocado entre las partes como en el siguiente ejemplo:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=frontier

This is a message with multiple parts in MIME format.
--frontier
Content-Type: text/plain

This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogIC AgPHA+VGhpcyBpcyB0aGUg
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2 h0bWw+Cg==
--frontier--
Fuentes:

http://www.webdeveloper.com/forum/sh...ch-file-in-PHP
http://en.wikipedia.org/wiki/MIME
__________________
Salu2!

Última edición por Italico76; 15/06/2013 a las 18:54