Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/10/2007, 14:43
Avatar de Mirovita
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]._.-.