Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/09/2004, 13:15
Avatar de HIa
HIa
 
Fecha de Ingreso: noviembre-2002
Ubicación: Cartago
Mensajes: 121
Antigüedad: 24 años
Puntos: 0
continuacion del codigo

mail.class.php

Código PHP:
<?php
class enviaMail {
    var 
$ContentType = "html/plain";
    var 
$headers = "";
    var 
$to;
    var 
$para = array();
    var 
$de = "";
    var 
$de_mail = "";
    var 
$titulo = "";
    var 
$mensajeHTML = "";
    var 
$mensajeTEXT = "";
    var 
$mensaje = "";
    var 
$responderA = array();
    var 
$cc = array();
    var 
$archivos_adjuntos = array();
    var 
$tipoMail = "html";
    var 
$importancia_n = 2;
    var 
$importancia_l = "";
    var 
$sender = "[email protected]";
    var 
$attach = ""; 
    
// Esta funcion agrega recipients a la lista de mail.
    
function cambia_direccion ($mail, $nombre = "", $prioridad = 2)
    {
    
$this->to = $mail;
    }
    function 
agrega_direccion($mail, $nombre = "", $prioridad = 2)
    {
        
$cur = count($this->para);
        
$this->para[$cur][0] = trim($mail);
        
$this->para[$cur][1] = $mail;
        
$this->para[$cur][2] = $prioridad;
    } 
    
// Esta funcion agrega a quien responder
    
function responder_a($mail, $nombre = "")
    {
        
$cur = count($this->responderA);
        
$this->responderA[$cur][0] = trim($mail);
        
$this->responderA[$cur][1] = $nombre;
    } 

    function 
cc_a($mail, $nombre = "")
    {
        
$cur = count($this->cc);
        
$this->cc[$cur][0] = trim($mail);
        
$this->cc[$cur][1] = $nombre;
    } 

    function 
tipò_mensaje($tipo)
    {
        if (
$tipo == "html") {
            
$this->tipoMail = "text/html;\n\t charset=\"iso-8859-15\"\n";
        } else {
            
$this->tipoMail = "text/plain;\n\t charset=\"iso-8859-15\"\n";
        } 
    } 

    function 
Ingresa_html ($msghtml)
    {
        
$msghtml = $msghtml?$msghtml:preg_replace("/\n/", "{br}", $msghtml) or die("neither text nor html part present.");
        
$msghtml = stripcslashes($msghtml);
        
$msghtml = chunk_split(base64_encode($msghtml));
        
$this->mensajeHTML = $msghtml;
    } 

    function 
ingresa_plain($msgplain)
    {
        
$msgplain = stripcslashes($msgplain);
        
$this->mensajeTEXT = $msgplain;
    } 
    
// Aqui agrego un archivo ajunto al mensaje
    
function importancia($nivel = 1)
    {
        switch (
$nivel) {
            case 
1:
                
$this->importancia_n = 1;
                
$this->importancia_l = "high";
                break;
            case 
2:
                
$this->importancia_n = 2;
                
$this->importancia_l = "medium";
                break;
            case 
3:
                
$this->importancia_n = 3;
                
$this->importancia_l = "low";
                break;
            default: ;
        } 
// switch
    
} 
    
// Agrego los archivos adjuntos
    
function agrega_adjunto($dir_uploads)
    { 
        
// Abrimos el directoriorio donde estan los archivos adjuntos por default uploads.
        
$dir = opendir($dir_uploads);
        
$Msg = "";
        while (
$archivo = readdir($dir)) {
            if ((
$archivo != ".") and ($archivo != "..")) {
                
$Msg .= "\n------=_OuterBoundary_000\n";
                
$Msg .= "Content-Type: application/octetstream;\n\tname=\"" . $archivo . "\"\n";
                
$Msg .= "Content-Transfer-Encoding: base64\n";
                
$Msg .= "Content-Disposition: attachment;\n\tfilename=\"" . $archivo . "\"\n\n";
                
$fd = fopen ("uploads/" . $archivo, "r");
                
$FileContent = fread($fd, filesize("uploads/" . $archivo));
                
fclose ($fd);
                
$FileContent = chunk_split(base64_encode($FileContent));
                
$Msg .= $FileContent;
                
$Msg .= "\n\n"; 
                
// Elimino el archivo para liberar espacio
            
} //if
        
} // while
        
return $Msg;
    } 

    function 
borrar_adjuntos($dir_uploads)
    {
        
$dir = opendir($dir_uploads);
        while (
$archivo = readdir($dir)) {
            if ((
$archivo != ".") and ($archivo != "..")) {
                @
unlink ("$dir_uploads/$archivo");
            } 
        } 
        unset(
$_SESSION['file']);
    } 
    
// Aqui creo los headers necesarios para el envio del mail...
    
function crea_headers ()
    {
        
$headers = "From: $this->de <$this->de_mail>\n";
        
$headers .= "Reply-To: $this->de <$this->de_mail>\n";
        
$headers .= "MIME-Version: 1.0\n";
        
$headers .= "Content-Type: multipart/mixed;\n\t boundary=----=_OuterBoundary_000\n";
        
$headers .= "X-Sender: $this->de <$this->de_mail\n";
        
$headers .= "X-Mailer: HIaMailSender @ Fnatasias Ecologicas\n";
        
$headers .= "X-Priority: $this->importancia_n\n";
        
$headers .= "X-MSMail-Priority: $this->importancia_l\r\n";
        
$headers .= "Return-Path: <$this->de_mail>\n";
        
$headers .= "This is a multi-part message in MIME format.\n";
        if (
count($this->cc) > 0) {
            
$cc = "";
            for(
$i = 0; $i < count($this->cc); $i++) {
                if (
$i != 0) {
                    
$cc .= ", ";
                } 
                
$cc .= "Cc: " . $this->cc[$i][0];
                if (
$this->cc[$i][1] != "") {
                    
$cc .= " <{$this->cc[$i][1]}>";
                } 
            } 
        } 
        
$headers .= "\r\n";
        
$this->headers = $headers;
    } 
    
// Esta funcion formatea el mensaje dependiendo de lo que haya en buffer??
    
function crea_titulo($titulo)
    {
        
$this->titulo = $titulo;
    } 

    function 
crea_cuerpo()
    {
        
$OB = "----=_OuterBoundary_000";
        
$IB = "----=_InnerBoundery_001";
        
$Msg = "This is a multi-part message in MIME format.\n";
        
$Msg .= "\n--" . $OB . "\n";
        
$Msg .= "Content-Type: multipart/alternative;\n\t boundary=\"" . $IB . "\"\n\n"; 
        
// plaintext section
        
$Msg .= "\n--" . $IB . "\n";
        
$Msg .= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
        
$Msg .= "Content-Transfer-Encoding: quoted-printable\n\n"; 
        
// plaintext goes here
        
$Msg .= $this->mensajeTEXT . "\n\n"; 
        
// html section
        
$Msg .= "\n--" . $IB . "\n";
        
$Msg .= "Content-Type: text/html;\n\tcharset=\"iso-8859-15\"\n";
        
$Msg .= "Content-Transfer-Encoding: base64\n\n"; 
        
// html goes here
        
$Msg .= $this->mensajeHTML . "\n\n"; 
        
// end of IB
        
$Msg .= "\n--" . $IB . "--\n"; 
        
// attachments
        // if ($this->attach != "") {
        // echo "<script> alert (\"Si hay archivos adjuntos\")</script>";
        
$Msg .= enviaMail::agrega_adjunto("uploads"); 
  
       
// message ends
        
$Msg .= "\n--" . $OB . "--\n";
       
//$this->mensaje = $Msg;
       
$new_pointer = fopen("mail_data.dat","a+");
       
$pone = fwrite($new_pointer, $Msg);
       
fclose($new_pointer);
    } 

    function 
envia_mail ()
    {
   
//     $to = "";
     //   for($i = 0; $i < count($this->para); $i++) {
     //       if ($i != 0) {
      //          $to .= ", ";
      //      } 
     //       $to .= $this->para[$i][0];
     //   } 
        // Obtengo el valor del sender a travez del php.ini
        
$new_from = $this->sender;
        
$old_from = ini_get("sendmail_from"); 
        
// Lo cambio por lo que quiera
        
ini_set("sendmail_from", $new_from); 
        
ini_set("max_execution_time", 60);
        
//echo "<script>alert (\"$to\") </script>";
        
$puntero = fopen("mail_data.dat","r");
        
$this->mensaje = fread($puntero, filesize("mail_data.dat"));
        
fclose($puntero);
        
mail($this->to, $this->titulo, $this->mensaje, $this->headers);
        
ini_set("sendmail_from", $old_from);
        
//$this->mensaje = "";
        
    
} 
} 

?>
Que errores puede haber trate usando archivos a tipo de buffer pero era ugual no se envian los correos o llegan si los adjuntos. En mi servidor loca l si que funciona....... no se que hacer es urgente

por si las dudaes las pruebas las hago en trypod.lycos.es no se si tendra algo que ver que nno funque
__________________
Siempre hay algo nuevo que aprender