Foros del Web » Programando para Internet » PHP »

adjuntar archivos

Estas en el tema de adjuntar archivos en el foro de PHP en Foros del Web. Buenas tardes... tengo una funcion q me adjunta los archivis al mail q voy a enviar oero cuando trato de aplicarla en otra pagina no ...
  #1 (permalink)  
Antiguo 05/10/2007, 14:43
Avatar de Mirovita  
Fecha de Ingreso: febrero-2005
Ubicación: Caracas-Venezuela
Mensajes: 840
Antigüedad: 19 años, 2 meses
Puntos: 10
adjuntar archivos

Buenas tardes... tengo una funcion q me adjunta los archivis al mail q voy a enviar oero cuando trato de aplicarla en otra pagina no me funciona cuando anexo archivos.. sera q alguien la ve y me dice q me puede estar fallando... no soy muy diestra con esto de los correos..

pero aqui les dejo la funcion:

Código PHP:
//Funcion envio de email con attachments            
function send_mail($emailaddress$fromaddress$emailsubject$body$attachments=false)
{
  
$eol="\r\n";
  
$mime_boundary='-----=' md5uniqid rand() ) ); //boundary para dividir los atachhments
  
$htmlalt_mime_boundary $mime_boundary."_htmlalt"//we must define a different MIME boundary for this section for the alternative to work properly in all email clients
 
  # Common Headers
  
$headers .= 'From: Comunicaciones Kentron.com.ve<'.$fromaddress.'>'.$eol;
  
$headers .= 'Reply-To: Comunicaciones Kentron.com.ve<'.$fromaddress.'>'.$eol;
  
$headers .= 'Return-Path: Comunicaciones Kentron.com.ve<'.$fromaddress.'>'.$eol;    // these two to set reply address
  
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
  
$headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters

  # Boundry for marking the split & Multitype Headers
  
$headers .= 'MIME-Version: 1.0'.$eol;

  

  
$msg "";     
 
  if (
$attachments !== false)
  {
    
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol//declaro en el HEADER esto para que funcionen los atacchments
    
for($i=0$i count($attachments); $i++)
    {
      if (
$attachments[$i]["file"]!='')
      {  
          
//echo "B";
        # File for Attachment
        
$file_name $attachments[$i]["file"];
        
$f_contents=$attachments[$i]["content"];//
        
$f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
        # Attachment
        
$msg .= "--".$mime_boundary.$eol//antes de cada attachment declaro el tipo divisor
        
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
        
$msg .= "Content-Transfer-Encoding: base64".$eol;
        
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol// !! This line needs TWO end of lines !! IMPORTANT !!
        
$msg .= $f_contents.$eol.$eol;       
      }
    }
    
$msg .= "--".$mime_boundary.$eol;///cierre del ultimo de los attachments
  

 
# Setup for text OR html -
                                            
$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol//abro el tipo alternativo para texto o html
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= strip_tags(str_replace("<br>""\n"$body)).$eol.$eol;

# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body.$eol.$eol;

//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol//cierro todos los alternativos

# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol//SIN ESTA LINEA FUNCIONA BIEN, CON ELLA DA PROBLEMAS.

  # SEND THE EMAIL
  
ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
  
mail($emailaddress$emailsubject$msg$headers);
  
ini_restore(sendmail_from);
  
//termina la funcion send_mail 
Código PHP:
# From Email Address
$fromaddress "[email protected]"////soporte kentron
$emailsubject "Nuevo incidente registrado en Soporte Kentron.com.ve"
Código PHP:
$qrySelAnex "SELECT * FROM DOC_INC WHERE IDINC = '".$idinc."'";
            
$res mysql_query($qrySelAnex,$link);
            
# arreglo para enviar attachments a funcion de envio de correos.
            
$attachments = array();
            
$cont=0;
            while(
$fila mysql_fetch_array($res))
            {
                    
$tipo $fila['TIPO'];
                    
$contenido $fila['DOC'];
                    
$nombrearch $fila['NOMBREARCH'];
                    
$attachments[$cont]["file"] = $nombrearch;
                    
$attachments[$cont]["content_type"] = $tipo;
                    
$attachments[$cont]["content"] = $contenido;
                    
$cont++;
            } 
Código PHP:
//aqui llamo ala funcion  y le paso los parametros
send_mail($emailUsuario$fromaddress,$emailsubject$body$attachments); 
__________________
.-._.-. [email protected]._.-.
  #2 (permalink)  
Antiguo 05/10/2007, 14:48
Avatar de @ndreX!  
Fecha de Ingreso: abril-2007
Mensajes: 161
Antigüedad: 17 años
Puntos: 4
Re: adjuntar archivos

¿Te muestra algún error?

Si es así puedes colocarlo acá.

Saludos.
  #3 (permalink)  
Antiguo 05/10/2007, 14:50
Avatar de Mirovita  
Fecha de Ingreso: febrero-2005
Ubicación: Caracas-Venezuela
Mensajes: 840
Antigüedad: 19 años, 2 meses
Puntos: 10
Re: adjuntar archivos

no no me lanza errores... solo no me envia el correo cuando adjunto un archivo... si mando el correo sin archivos adjuntos si lo manda bien
__________________
.-._.-. [email protected]._.-.
  #4 (permalink)  
Antiguo 06/10/2007, 22:00
 
Fecha de Ingreso: abril-2006
Mensajes: 1.128
Antigüedad: 18 años
Puntos: 33
Re: adjuntar archivos

Mirovita:
Honestamente, NO veo por ningun lado
que el "Attachment" sea efectivamente
adjuntado al correo.
Saludos
Franco
  #5 (permalink)  
Antiguo 07/10/2007, 05:22
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Re: adjuntar archivos

se que a mucha gente no le gusta usar clases de terceros, y menos si son muy pesadas, pero, has pensado en usar phpmailer? yo la uso y me va de fabula, no he tenido nunca ningun problema, y he trabajado con diferentes servidores en los que solo tenia habilitada la funcion mail() sin poder usar smtp, y sigue funcionando genial.

puedes hecharle un vistazo aqui: http://phpmailer.sourceforge.net/

Saludos!
  #6 (permalink)  
Antiguo 08/10/2007, 13:37
Avatar de elquique  
Fecha de Ingreso: marzo-2004
Ubicación: Florida, Uruguay
Mensajes: 2.495
Antigüedad: 20 años, 1 mes
Puntos: 78
Re: adjuntar archivos

Se puede descartar que la funciona esta correcta ??

De ser así, debe ser un fallo en la generación del array llamado $attachments, y la causa puede estar en que intente atachar muchos archivos y se pase de peso, o algun archivo de tipo no permitido, etc.

Que tal si pruebas enviar el send_mail sin realizar el while, para tener mejor control ...
__________________
Blog Jorge Oyhenard | Tutoriales Photoshop
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 21:51.