Ver Mensaje Individual
  #7 (permalink)  
Antiguo 29/02/2004, 19:34
Avatar de Manoloweb
Manoloweb
 
Fecha de Ingreso: enero-2002
Ubicación: Monterrey
Mensajes: 2.454
Antigüedad: 22 años, 3 meses
Puntos: 5
Código PHP:
<?
/* **********************************************************************
 *
 *    Clase:            Nexus MIME Mail ('nxs_mimemail.inc.php')
 *    Version:            1.0
 *    Autor:            Alejandro Garcia Gonzalez <[email protected]>    
 *    Web:                [url]http://nexus.nuestroweb.com[/url]
 *
 * Descripcion:
 * Clase para poder enviar correos tipo MIME, con las siguientes
 * caracteristicas:
 *
 * + Solo Texto Plano
 * + HTML
 * + Texto Plano con adjuntos
 * + HTML con Adjuntos
 * + HTML con Imagenes Embebidas
 * + HTML con Imagenes Embebidas y Adjuntos
 * 
 * Esta clase esta desarrollada a partir de la exelente explicacion
 * encontrada en: [url]http://www.rinconastur.com/php/php64b.php[/url] 'Memorias
 * de un aprendiz' (Muchas Gracias). Lo demas fue revisando el codigo
 * fuente que genera Evolution ([url]www.ximian.com[/url]) y adaptarlo.
 *
 * ********************************************************************** */

class nxs_mimemail {
    
    
/* 
      * Variables Publicas
     * POR HACER: Depurar
     */
    
var $mail_from "Anonimo <[email protected]>";
    var 
$mail_to;
    var 
$mail_cc;
    var 
$mail_bcc;
    var 
$mail_subject "Sin Asunto";
    var 
$mail_text;
    var 
$mail_html;
    var 
$adjuntos_indice;
    var 
$adjuntos = array();
    var 
$adjuntos_img = array();
    var 
$separador_mix;
    var 
$seperador_rel;
    var 
$separador_alt;
    var 
$mail_type;
    var 
$cabecera;
    var 
$mensaje;
    var 
$msg_error "si";             // "si" | "no" | "halt"
   
var $tipos_mime = array(); 

    
/*
     * void nxs_mimemail();
     * Constructor.
     */
    
function nxs_mimemail(){
        
$this->separador_mix "=-nxs_mix_" md5(uniqid(rand()));
        
$this->separador_rel "=-nxs_rel_" md5(uniqid(rand()));
        
$this->separador_alt "=-nxs_alt_" md5(uniqid(rand()));
        
$this->adjuntos_indice 0;
        
$this->tipos_mime = array(
            
'gif'  => 'image/gif',
            
'jpg'  => 'image/jpeg',
            
'jpeg' => 'image/jpeg',
            
'jpe'  => 'image/jpeg',
            
'bmp'  => 'image/bmp',
            
'png'  => 'image/png',
            
'tif'  => 'image/tiff',
            
'tiff' => 'image/tiff',
            
'swf'  => 'application/x-shockwave-flash',
            
'doc'  => 'application/msword',
            
'xls'  => 'application/vnd.ms-excel',
            
'ppt'  => 'application/vnd.ms-powerpoint',
            
'pdf'  => 'application/pdf',
            
'ps'   => 'application/postscript',
            
'eps'  => 'application/postscript',
            
'rtf'  => 'application/rtf',
            
'bz2'  => 'application/x-bzip2',
            
'gz'   => 'application/x-gzip',
            
'tgz'  => 'application/x-gzip',
            
'tar'  => 'application/x-tar',
            
'zip'  => 'application/zip',
            
'html' => 'text/html',
            
'htm'  => 'text/html',
            
'txt'  => 'text/plain',
            
'css'  => 'text/css'
            
);

        if(!
defined('SALTO')){
            
define('SALTO'"\r\n"TRUE);
        }
    }

    
/*
     * void correo_de(string $mail_from, [string $nombre]);
     * Se asigna la direccion de correo del remitente. Opcionalmente
     * tambien se puede especificar el nombre del contacto.
     * $mail_from - Direccion de correo del remitente.
     * $nombre - Nombre del remitente (opcional).
     */
    
function correo_de($mail_from$nombre ""){
        if (
$this->valida_correo($mail_from)){
            if (!empty(
$nombre)){
                
$mail_from "$nombre <$mail_from>";
            }
            
$this->mail_from $mail_from;
        }
        else {
            
$this->mail_from "Anonimo <[email protected]>";
        }
    }

    
/*
     * bool agregar_para(string $mail_to, [string $nombre]);
     * Se asignan las direcciones de correos destino. Opcionalmente
     * tambien se puede especificar el nombre del contacto.
     * $mail_to - Direccion de correo destino.
     * $nombre - Nombre del correo destino (opcional).
     */
    
function agregar_para($mail_to$nombre ""){
        if (
$this->valida_correo($mail_to)){
            if (!empty(
$nombre)){
                
$mail_to "$nombre <$mail_to>";
            }
            if (empty(
$this->mail_to)){
                
$this->mail_to $mail_to;
                return 
true;
            }
            else {
                
$this->mail_to .= ", " $mail_to;
                return 
true;
            }
        }
        return 
false;
    }

    
/*
     * bool agregar_cc(string $mail_cc, [string $nombre]);
     * Se asignan las copias de correo destino. Opcionalmente
     * tambien se puede especificar el nombre del contacto.
     * $mail_cc - Direccion de copia de correo destino.
     * $nombre - Nombre del copia del correo destino (opcional).
     */
    
function agregar_cc($mail_cc$nombre ""){
        if (
$this->valida_correo($mail_cc)){
            if (!empty(
$nombre)){
                
$mail_cc "$nombre <$mail_cc>";
            }
            if (empty(
$this->mail_cc)){
                
$this->mail_cc $mail_cc;
                return 
true;
            }
            else {
                
$this->mail_cc .= ", " $mail_cc;
                return 
true;
            }
        }
        return 
false;
    }
    
    
/*
     * bool agregar_bcc(string $mail_bcc, [string $nombre]);
     * Se asignan las copias ocuptas de correo destino. Opcionalmente 
     * tambien se puede especificar el nombre del contacto.
     * $mail_bcc - Direccion de copia de correo destino.
     * $nombre - Nombre del correo destino (opcional).
     */
    
function agregar_bcc($mail_bcc$nombre ""){
        if (
$this->valida_correo($mail_bcc)){
            if (!empty(
$nombre)){
                
$mail_bcc "$nombre <$mail_bcc>";
            }
            if (empty(
$this->mail_bcc)){
                
$this->mail_bcc $mail_bcc;
                return 
true;
            }
            else {
                
$this->mail_bcc .= ", " $mail_bcc;
                return 
true;
            }
        }
        return 
false;
    }
    
    
/*
     * bool asunto(string $texto);
     * Se asigna el asunto del mensaje, en caso de no hacerlo
     * se asignara el asunto predeterminado.
     * $texto - Cadena de texto que va en el asunto.
     */
    
function asunto($texto){
        if (!empty(
$texto)){
            
$this->mail_subject $texto;
        }
    }

    
/*
     * void mensaje_texto(string $mensaje);
     * Se agrega el mensaje en texto plano.
     * $mensaje - Mensaje en texto plano.
     */
    
function mensaje_texto($mensaje){
        if (!empty(
$mensaje)){
            
$this->mail_text $mensaje;
        }
    }

    
/*
     * void mensaje_html(string $mensaje);
     * Se agrega el mensaje en html.
     * $mensaje - Mensaje en html.
     */
    
function mensaje_html($mensaje){
        if (!empty(
$mensaje)){
            
$this->mail_html $mensaje;
        }
    }

    
/*
     * void crear_correo([string $de], [string $para], [string $asunto], [string $texto], [string $html]);
     * Esta funcion se encarga de hacer un poco mas rapida la inclusion de
     * los datos basicos que se requieren para armar un correo.
     * Este solo es un atajo. Todos los valores son opcionales.
     * $de - Direccion de correo del remitente
     * $para - Direccion de correo del destinatario
     * $texto - Mensaje en Texto Plano
     * $html - Mensaje en formato HTML
     */
    
function crear_correo($de ""$para ""$asunto ""$texto ""$html ""){
        
$this->correo_de($de);
        
$this->correo_para($para);
        
$this->asunto($asunto);
        
$this->mensaje_texto($texto);
        
$this->mensaje_html($html);
    }
    
    
/* 
     * void agregar_adjunto(mixed $archivo, string $nombre, [string $tipo]);
     * Funcion para agregar archivos adjuntos al correo.
     * $archivo - Resultado del fopen del archivo.
     * $tipo - Tipo del archivo, predeterminadamente "application/octet-stream".
     * $nombre - Nombre del archivo.
     */
    
function agregar_adjunto($archivo$nombre$tipo ""){
        if (empty(
$tipo)){$tipo $this->revisar_mime($nombre);}
        
$this->adjuntos[$this->adjuntos_indice][archivo] = chunk_split(base64_encode($archivo));
        
$this->adjuntos[$this->adjuntos_indice][nombre] = $nombre;
        
$this->adjuntos[$this->adjuntos_indice][tipo] = $tipo;
        
$this->adjuntos[$this->adjuntos_indice][embebido] = false;
        
$this->adjuntos_indice++;
    }

    
/*
     * void armar_cabecera();
     * Funcion encargada de armar la cabecera del correo.
     */
    
function armar_cabecera($content_type){
        
$this->cabecera "MIME-Version: 1.0" SALTO;
        if (!empty(
$this->mail_from)){
            
$this->cabecera .= "Wrom: ZUIVOTQNQEMSFDULHPQQWOYIYZUNN
            $this->cabecera .= "
Reply-To" . $this->mail_from . SALTO;
        }
        if (!empty($this->mail_cc)){
            $this->cabecera .= "
Cc" . $this->mail_cc . SALTO;
        }    
        if (!empty($this->mail_bcc)){
            $this->cabecera .= "
Bcc" . $this->mail_bcc . SALTO;
        }
        $this->cabecera .= "
X-MailerneXus MIME Mail PHP/". phpversion() . SALTO;
        $this->cabecera .= $content_type . SALTO . SALTO;
    }
... CONTINUA...
__________________
Manoloweb