Ver Mensaje Individual
  #4 (permalink)  
Antiguo 27/07/2009, 14:28
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: Input file a mi correo

De hecho la otra forma es más complicada ya que tienes que codificar el archivo usando Base64 de preferencia, luego crear las cabeceras MIME y codificar tu correo, aquí tienes un ejemplo de como hacerlo con un archivo:
Código php:
Ver original
  1. <?php
  2. // Para quien es el email
  3. // Subject
  4. $subject = 'Ejemplo de Email con Attachment';
  5. // Este es el boundary para separar los correos, debe de ser aleatorio
  6. $random_hash = md5(date('r', time()));
  7. // Definir las cabeceras basicas separadas por \r\n
  8. $headers = "From: [email protected]\r\nReply-To: [email protected]";
  9. // Agregar que es un mail mixto y el separador
  10. $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
  11. // Lees y agregas el archivo que hayas subido
  12. $attachment = chunk_split(base64_encode($_FILES['archivo']['tmp_name']));
  13. // Crear el correo con las cabeceras
  14. ?>
  15. --PHP-mixed-<?php echo $random_hash; ?>
  16. Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
  17.  
  18. --PHP-alt-<?php echo $random_hash; ?>
  19. Content-Type: text/plain; charset="iso-8859-1"
  20. Content-Transfer-Encoding: 7bit
  21.  
  22. Texto sin HTML (cuerpo del mensaje)
  23.  
  24. --PHP-alt-<?php echo $random_hash; ?>
  25. Content-Type: text/html; charset="iso-8859-1"
  26. Content-Transfer-Encoding: 7bit
  27.  
  28. <h1>Aqui va el mail pero con HTML</h1>
  29.  
  30. --PHP-alt-<?php echo $random_hash; ?>--
  31.  
  32. --PHP-mixed-<?php echo $random_hash; ?>
  33. Content-Type: application/zip; name="archivo.ext"
  34. Content-Transfer-Encoding: base64
  35. Content-Disposition: attachment
  36.  
  37. <?php echo $attachment; ?>
  38. --PHP-mixed-<?php echo $random_hash; ?>--
  39.  
  40. <?php
  41. // Obtienes el mail usando ob_get_clean();
  42. $message = ob_get_clean();
  43. // Se envia el correo
  44. if (mail( $to, $subject, $message, $headers )) {
  45.     echo "Envio exitoso";
  46. } else {
  47.     echo "Error al enviar el Mail";
  48. }

Como ves el codificar el correo es más complicado a si usas PHPMailer que tiene métodos para hacerlo de forma más sencilla.

Saludos.