Foros del Web » Programando para Internet » PHP »

Enviar mensajes de correo masivo AYUDA... + adjuntos

Estas en el tema de Enviar mensajes de correo masivo AYUDA... + adjuntos en el foro de PHP en Foros del Web. Hola la cuestion es esta necesito hacer para la empresa una aplicacion que envie emails a todos los usuarios que se han registrado en la ...
  #1 (permalink)  
Antiguo 05/09/2004, 13:15
Avatar de HIa
HIa
 
Fecha de Ingreso: noviembre-2002
Ubicación: Cartago
Mensajes: 121
Antigüedad: 21 años, 5 meses
Puntos: 0
Enviar mensajes de correo masivo AYUDA... + adjuntos

Hola la cuestion es esta necesito hacer para la empresa una aplicacion que envie emails a todos los usuarios que se han registrado en la base de datos. Ok ya tengo dicho script y funciona a las mil maravillas excepto por lo mas importante los archivos adjuntos.... simplemente no se envian .... que pasara aqui les envio el codigo completo.

spam.php
Código PHP:
<?php
if (isset($_GET['completo'])) {
    
session_start();
    
session_name("upload");
    include(
"mail.class.php");
    
$mail = new enviaMail;
    
$puntero fopen("email.dat""r");
    while (
$puntero && !feof($puntero)) {
        
$buffer = @fgets($puntero4096);
        
$sql "SELECT * FROM cliente WHERE id = '$buffer'";
        
$conecta mysql_connect("localhost""xxxx""xxxx") or die ("1" mysql_error());
        
$base mysql_select_db("xxxx"$conecta) or die ("2" mysql_error());
        
$sql2 mysql_query($sql) or die ("3" mysql_error());
        
$resultados mysql_num_rows($sql2);
        if (
$resultados == 0) {
            
mysql_free_result($sql2);
        } else {
            
$mail->importancia(2);
            
$mail->de "Fantasías Ecológicas Mayorista de Viajes";
            
$mail->de_mail "[email protected]";
            
$mail->responder_a("[email protected]""Fantasías Ecológicas Mayorista de Viajes");
            
$mail->crea_headers(); 
            
$mail->Ingresa_html($_POST['mensaje']);
            
$mail->ingresa_plain("Este mensaje no esta soportado por tu navegador de correo");
                
                
// if (isset($_SESSION['file'])) {
                // $mail->agrega_adjunto();
                // }
           
$mail->crea_titulo($_POST['titulo']);
           
$mail->crea_cuerpo();
            while (
$resultados mysql_fetch_array($sql2)) {
                
// Verifico si hay archivcos adjuntos
                // pongo la iportancia del mensaje
                // $mail->tipò_mensaje("html");
                
                
$mail->cambia_direccion($resultados['email'], $resultados['nombre']);
                
$mail->envia_mail();
            } 
            
// Ahora que ya se envio el mail pues borro los attachments que subi
            
$mail->borrar_adjuntos("uploads");
        } 
    } 
    
fclose($puntero);
    
mysql_close($conecta);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SPAM!!!t</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
</script>
<body>


//Aqui va el codigo del form de donde obtengo los datos p enviar el correo
</html>
__________________
Siempre hay algo nuevo que aprender
  #2 (permalink)  
Antiguo 05/09/2004, 13:15
Avatar de HIa
HIa
 
Fecha de Ingreso: noviembre-2002
Ubicación: Cartago
Mensajes: 121
Antigüedad: 21 años, 5 meses
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($fdfilesize("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($punterofilesize("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
  #3 (permalink)  
Antiguo 06/09/2004, 06:11
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Todo servicio de hosting gratutito como ... trypod.lycos.es puede darte problemas, pero lo peor no es eso sino que no puedes reclamar ... ni ver los log de envios .. ni nada.

Por lo demás .. te recomendaría usar la classe:

PHP Mailer
http://phpmailer.sourceforge.net

Que permite enviar e-mail con archivos adjuntos entre otras cosas como la de enviar los e-mails por SMTP directo (no dependiendo del de "lycos" pudiendo usar otro)

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 03:46.