Foros del Web » Programando para Internet » PHP »

Adjuntos!

Estas en el tema de Adjuntos! en el foro de PHP en Foros del Web. Hola gente... tengo un script que me adjunta archivos y los manda por mail.. PEEEEEEEEEEEEERO.. con Hotmail.. anda de maravillas.. a la hora de mandar ...
  #1 (permalink)  
Antiguo 07/12/2004, 12:21
 
Fecha de Ingreso: noviembre-2004
Mensajes: 75
Antigüedad: 19 años, 5 meses
Puntos: 0
Adjuntos!

Hola gente...
tengo un script que me adjunta archivos y los manda por mail..
PEEEEEEEEEEEEERO..
con Hotmail.. anda de maravillas.. a la hora de mandar a un POP3 y recibirlo con el Outlook.... muestra el código HTML y no adjunta el archivo....


¿PORQUÉ?
  #2 (permalink)  
Antiguo 07/12/2004, 13:22
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Y que "código" usas .. .. sobre todo como estás generando tu e-mail .. (recuerda que no somos adivinos .. necesitamos ver algo para "deducir" cosas normalmente).

Seguro que en tu "Outlook" o cliente de correo que uses no estás filtrando o eliminando archivos adjuntos .. (El SP2 de Windows XP bloquea por defecto archivo adjuntos, no deja ver archivos referenciados (a un URL dado ..) etc .. son cosas que tienes que "permitir" si tu quieres).

Un saludo,
  #3 (permalink)  
Antiguo 07/12/2004, 14:20
 
Fecha de Ingreso: noviembre-2004
Mensajes: 75
Antigüedad: 19 años, 5 meses
Puntos: 0
El script está compuesto por dos archivos..

Código PHP:
<?
    
include("sendmail.class.php");

    
$mail = new sendmail();

    
$mail->SetCharSet("ISO-8859-1");

    
$mail->from("Remitente");

    
$mail->to("$suemail");

    
$mail->subject("Asunto");

    
$mail->text("CODIGO HTML");

    
$mail->attachment("$foto");

    
$mail->send();
    echo 
"<SCRIPT LANGUAGE=\"javascript\">location.href =\"ok.php\";</SCRIPT>" 
?>
Este es el otro archivo (sendmail.class.php)

Código PHP:
<?
    
class sendmail
    
{
        
// Variable deklarieren
        
var $emailheader "";
        var 
$textheader "";
        var 
$textboundary "";
        var 
$emailboundary "";
        var 
$charset "";
        var 
$betreff "";
        var 
$empfaenger "";
        var 
$attachment = array();
        var 
$cc = array();
        var 
$bcc = array();

        
// Konstruktor
        
function sendmail()
        {
            
$this->textboundary uniqid(time());
            
$this->emailboundary uniqid(time());
            
$this->charset "ISO-8859-1";
        }

        
// Funktion zum setzen des CharSet´s
        
function SetCharSet($char)
        {
            
$this->charset $char;
        }


        
// Funktion die überprüft ob die E-Mailadresse korrekt ist
        
function Validate_email($mailadresse)
        {
            if(!
preg_match("/[a-z0-9_-]+(\.[a-z0-9_-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})/i",$mailadresse))
            {
                die(
'La Dirección '.$mailadresse.' No es válida!!!');
            }
            return 
$mailadresse;
        }

        
// Von wem die Email kommt in den Header setzen
        
function from($name,$email)
        {
            
$this->emailheader .= 'From: '.$name.'<'.$email.'>'."\r\n";
        }

        
// Funktion um den Adressaten anzugeben
        
function to($to)
        {
            
$this->empfaenger $this->Validate_email($to);
        }

        
// Funktion zum senden einer Kopie an Cc Empfänger
        
function cc($kopie_an_empfaenger)
        {
            
$this->cc[] = $kopie_an_empfaenger;
        }

        
// Funktion zum senden einer Kopie an Bcc Empfänger
        
function bcc($kopie_an_empfaenger)
        {
            
$this->bcc[] = $kopie_an_empfaenger;
        }

        
// Erstellt den Header der Mime-Mail
        
function makeMimeMail()
        {
            if(
count($this->cc) > 0)
            {
                
$this->emailheader .= 'Cc: ';
                for(
$i=0;$i<count($this->cc);$i++)
                {
                    if(
$i 0$this->emailheader .= ',';
                    
$this->emailheader .= $this->Validate_email($this->cc[$i]);
                }
                
$this->emailheader .= "\r\n";
            }

            if(
count($this->bcc) > 0)
            {
                
$this->emailheader .= 'Bcc: ';
                for(
$j=0;$j<count($this->bcc);$j++)
                {
                    if(
$j 0$this->emailheader .= ',';
                    
$this->emailheader .= $this->Validate_email($this->bcc[$j]);
                }
                
$this->emailheader .= "\r\n";
            }
            
$this->emailheader .= 'MIME-Version: 1.0'."\r\n";
        }

        
// Funktion für den Betreff anzugeben
        
function subject($subject)
        {
            
$this->betreff $subject;
        }

        
// Textdaten in Email Header packen
        
function text($text)
        {
            
$this->textheader .= 'Content-Type: multipart/alternative; boundary="'.$this->textboundary.'"'."\r\n\r\n";
            
$this->textheader .= '--'.$this->textboundary."\r\n";
            
$this->textheader .= 'Content-Type: text/html; charset="'.$this->charset.'"'."\r\n";
            
$this->textheader .= 'Content-Transfer-Encoding: quoted-printable'."\r\n\r\n";
            
$this->textheader .= '<html><body>'.$text.'</body></html>'."\r\n\r\n";
            
$this->textheader .= '--'.$this->textboundary.'--'."\r\n\r\n";
        }

        
// Funktion zum anhängen für Attachments in der Email
        
function attachment($datei)
        {
            
// Überprüfen ob File Existiert
            
if(is_file($datei))
            {
                
// Header für Attachment erzeugen
                
$attachment_header '--'.$this->emailboundary."\r\n" ;
                
$attachment_header .= 'Content-Type: application/octet-stream; name="'.basename($datei).'"'."\r\n";
                
$attachment_header .= 'Content-Transfer-Encoding: base64'."\r\n";
                
$attachment_header .= 'Content-Disposition: attachment; filename="'.basename($datei).'"'."\r\n\r\n";

                
// Daten der Datei einlesen, in das BASE64 Format formatieren und auf max 72 Zeichen pro Zeile
                // aufteilen
                
$file['inhalt'] = fread(fopen($datei,"rb"),filesize($datei));
                
$file['inhalt'] = base64_encode($file['inhalt']);
                
$file['inhalt'] = chunk_split($file['inhalt'],72);

                
// Attachment mit Header in der Klassenvariable speichern
                
$this->attachment[] = $attachment_header.$file['inhalt']."\r\n";
            }
            else
            {
                die(
'El Archivo "'.$datei.'" No Existe'."\r\n");
            }
        }

        
// Funktion zum erstellen des Kompletten Headers der Email
        // Senden der Email
        
function send()
        {
            
$this->makeMimeMail();

            
$header $this->emailheader;

            
// Überprüfen ob Attachments angehängt wurden
            
if(count($this->attachment)>0)
            {
                
$header .= 'Content-Type: multipart/mixed; boundary="'.$this->emailboundary.'"'."\r\n\r\n";
                
$header .= '--'.$this->emailboundary."\r\n";
                
$header .= $this->textheader;

                if(
count($this->attachment) > 0$header .= implode("",$this->attachment);

                
$header .= '--'.$this->emailboundary.'--';
            }
            else
            {
                
$header .= $this->textheader;
            }
            
// Versenden der Mail
            
mail("$this->empfaenger",$this->betreff,"",$header);

            
$this->deletememory();
        }

        
// Diese Funktion ist nur zum testen
        
function deletememory()
        {
            unset(
$this->emailheader);
            unset(
$this->textheader);
            unset(
$this->attachment);
        }
    }
?>
  #4 (permalink)  
Antiguo 07/12/2004, 15:03
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues .. no sé que decirte .. es decir .. si esa classe que compone las cabecras necesarias para codificar tu archivo y formar el mail "multiparte" lo hace bien (lo ves en un cliente de correo determinado) .. debería funcionar igual en todo cliente de correo.

No sé si conoces:
PHP Mailer
http://phpmailer.sourceforge.net

Te lo comento por qué es una excelente classe para envio de e-mails con archivos adjuntos, HTML, y un montón de cosas más. Pruebala. Por mi parte no he tenido problemas con archivos adjuntos ...

Un saludo,
  #5 (permalink)  
Antiguo 07/12/2004, 15:14
 
Fecha de Ingreso: noviembre-2004
Mensajes: 75
Antigüedad: 19 años, 5 meses
Puntos: 0
manual en español.. ¿existe para esa clase?
  #6 (permalink)  
Antiguo 07/12/2004, 15:23
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues manual "oficial" en español no .. pero si un tutorial en español de uso:

http://www.programacion.com/php/articulo/phpmailer/
(de todas formas .. los ejemplos que tienes en su web oficial son bien "claros" .. pruebalos).

Un saludo,
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 18:07.