Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/09/2011, 11:18
Avatar de BaByRoDrI
BaByRoDrI
 
Fecha de Ingreso: julio-2009
Ubicación: Mexico
Mensajes: 60
Antigüedad: 14 años, 10 meses
Puntos: 1
Pregunta Adjunto "noname"

He estado creando un mailer para poder enviar información a mis usuarios y uno de los requerimientos es poder mandar un archivo adjunto, para lo cual he usado el siguiente código:

Código PHP:
Ver original
  1. <?php
  2.  
  3.             $attachment          = $_FILES['file'];
  4.             $attachtmp          = $_FILES['file']['tmp_name'];
  5.             $attachname          = $_FILES['file']['name'];
  6.             $attachsize          = $_FILES['file']['size'];
  7.             $attachtype          = $_FILES['file']['type'];
  8.  
  9.             if (is_uploaded_file($attachtmp)) {
  10.                 @move_uploaded_file($attachtmp, "./$attachname") or die ("El archivo que intentas subir no se pudo copiar al servidor");
  11.                 $content = fread(fopen($attachname,"r"), filesize($attachname));
  12.                 $content = chunk_split(base64_encode($content));
  13.                 $uid = strtoupper(md5(uniqid(time())));
  14.                 //$name = basename($attachment['name']);
  15.             }
  16.  
  17.                     $header = "From: $realname <$from>\r\nReply-To: $replyto\r\n";
  18.                     $header .= "MIME-Version: 1.0\r\n";
  19.                     if ($attachment) $header .= "Content-Type: multipart/mixed; boundary=$uid\r\n";
  20.                     if ($attachment) $header .= "--$uid\r\n";
  21.                     $header .= "Content-Type: text/$contenttype\r\n";
  22.                     $header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
  23.                     $header .= "$message\r\n";
  24.                     if ($attachment) $header .= "--$uid\r\n";
  25.                     If ($attachment) $header .= "Content-Type: $attachtype; name=\"$attachname\"\r\n";
  26.                     If ($attachment) $header .= "Content-Transfer-Encoding: base64\r\n";
  27.                     If ($attachment) $header .= "Content-Disposition: attachment; name=\"$attachname\"\r\n\r\n";
  28.                     If ($attachment) $header .= "$content\r\n";
  29.                     If ($attachment) $header .= "--$uid--";
  30.                     @mail($to, $subject, "", $header);
  31.  
  32. ?>
El problema recae en que si no defino ningun archivo en el formulario, me llega bien el correo pero con un adjunto llamado noname, igual que si adjunto un archivo me llegan 2, el que yo subo y otro llamado noname :S

No se a que se deba esto ya me desespero :(.