Foros del Web » Programando para Internet » PHP »

urgente: problema con mail

Estas en el tema de urgente: problema con mail en el foro de PHP en Foros del Web. Hola a todos, quisiera enviar correos en formato html con la función mail, tengo lo siguiente: <?php $hdr="MIME-Version: 1.0\n"; $hdr.="Content-type: text/html; charset=iso-8859-1\n"; $hdr.="Content-Transfer-Encoding: 8bit\n"; $hdr.="X-Priority: ...
  #1 (permalink)  
Antiguo 11/12/2003, 21:44
 
Fecha de Ingreso: septiembre-2003
Mensajes: 248
Antigüedad: 20 años, 7 meses
Puntos: 2
urgente: problema con mail

Hola a todos, quisiera enviar correos en formato html con la función mail, tengo lo siguiente:
<?php

$hdr="MIME-Version: 1.0\n";
$hdr.="Content-type: text/html; charset=iso-8859-1\n";
$hdr.="Content-Transfer-Encoding: 8bit\n";
$hdr.="X-Priority: 1\n";
$hdr.="X-MSMail-Priority: High\n";
$hdr.="From: \"Nombre\" <[email protected]>\n";

$bod="<html>\n<body bgColor='#E0ECF8'>\n";
$bod.="<b>Esto debe verse en negrita</b> y esto no\n";
$bod.="<img src='http://www.miservidor.com/logoinfo2.gif'>\n";
$bod.="</body>\n";
$bod.=" </html>\n";


if(mail("[email protected]","Asunto",$bod,$hdr))
{
echo("ok");
}
else
{
echo("error");
}

?>
el problema es que, aunque llega el correo, no muestra la imagen
si hago en una ventana nueva: http://www.miservidor.com/logoinfo2.gif
me muestra la imagen, y cuando reabro mi bandeja de entrada del correo destino si la muestra
como hago para que me muestre la imagen en el correo destino sin necesidad de cargar la imagen en una ventana nueva?
Gracias a todos
__________________
Jose A

Última edición por j_aspillaga; 11/12/2003 a las 21:47
  #2 (permalink)  
Antiguo 12/12/2003, 00:17
Avatar de nuevo  
Fecha de Ingreso: mayo-2003
Ubicación: Spain
Mensajes: 2.009
Antigüedad: 20 años, 11 meses
Puntos: 2
puedes usar una classe...

Código PHP:
<?php

/**
* Clase para el envio de email(s) via SMTP o mail()
*
* Clase para el evio multiple o simple de email(s) via SMTP o
* por medio de la funcion mail().
* Tambien comprueba si los email son validos o no y en
* la conexion al servidor puede ser con o sin login de usuario.
*
* @version   2.0a
* @author MSDark ([email protected])
* @copyright MSDark
*/
class email
{
/**
* Contiene el asunto del email  enviar
*
* @var string
* @acces private
*
*/
var $asunto;
/**
* Contiene las direcciones de destino
*
* @var string
* @acces private
*
*/
var $direcciones;
/**
* Remitente del email
*
* @var string
* @acces private
*
*/
var $remitente;
/**
* Contiene el mensaje a enviar solo texto plano
*
* @var string
* @acces private
*
*/
var $mensaje;
/**
* Contiene si el email fue enviado o no
*
* Guarda un valor en caso de que el mail haya sido enviado.
* @var booleano
* @acces private
*
*/
var $enviado;
/**
* Contiene el errro ocurrido en ejecucion
*
* @var string
* @acces private
*
*/
var $error;
/**
* Contiene un valor si los email son validos o no
*
* @var booleano
* @acces private
*
*/
var $comprobar;


/**
* Constructor de la clase
*
* Setea el valor de asunto, mensaje,remitente
* y direcciones, mada a revisar los email o devuelve cierto error.
*
* @param asunto = asunto del email
* @param direccion = direccion del email
* @param mensaje =mensaje de email
* @param remitente = remitente del email
* @acces private
*/
function email($asunto,$direccion,$mensaje,$remitente)
{
 if(empty(
$asunto) || empty($direccion) || empty($mensaje) || empty($remitente) ){
 return 
$this->error(1);
 }else{
 
$this->asunto=$asunto;
 
$this->direcciones=$direccion;
 
$this->mensaje=$mensaje;
 
$this->remitente=$remitente;

 
$this->comprobar($direccion,$remitente);
  if(!
$this->comprobar){
    return 
$this->error(2);
    }
//if

 
}   //if-else
}  //funcion

/**
* Setea el error que pueda ocurrir durante ejecucion
*
* @param e = error ocurrido durante ejecucion
* @acces private
*
*/
function error($e)
{
 switch(
$e){
 case 
1:
 return 
$this->error="No has completado todos los datos";
 break;
 case 
2:
 return 
$this->error="El/los email(s) de remitente y/o destino son invalidos";
 break;
 case 
3:
 return 
$this->error="No se han establecido los campos necesarios";
 break;
 case 
4:
 return 
$this->error="No se puede enviar el/los email(s)";
 break;
 case 
5:
 return 
$this->error="No se puede realizar conexion con el servidor SMTP <b>$errn: error</b>";
 break;
 case 
6:
 return 
$this->error="No se puede establecer comunicacion con el servidor";
 break;
 case 
7:
 return 
$this->error="No se puede cerrar conexion con el servidor";
 break;
 default:
 break;
 }
//switch
//funcion



/**
* Devuelve el error ocurrido
*
* @acces private
*
* @return string El error ocurrido
*/
function errores()
{
return 
$this->error;
}
//funcion



/**
* Comprueba los email de destino y remitente
*
* Comprueba si ambos campos son validos es decir contiene @, '.' y un dominio valido.
* @param direccion = direccion del email
* @param remitente = remitente del email{
* @acces private
*
* @return booleano
*/
function comprobar($direccion,$remitente)
{
$this->comprobar=false;
 if((@
is_array($direccion)) && (@is_array($remitente))){

    for(
$i=0$i<@count($direccion); $i++){
   if ((@
strlen($direccion[$i]) >= 3) && (@substr_count($direccion[$i],"@") == 1) && (@substr($direccion[$i],0,1) != "@") && (@substr($direccion[$i],@strlen($direccion[$i])-1,1) != "@") && (@strlen($remitente[$i]) >= 6) && (@substr_count($remitente[$i],"@") == 1) && (@substr($remitente[$i],0,1) != "@") && (@substr($direccion[$i],@strlen($remitente[$i])-1,1) != "@")){
    if ((!@
strstr($direccion[$i],"'")) && (!@strstr($direccion[$i],"\"")) && (!@strstr($direccion[$i],"\\")) && (!@strstr($direccion[$i],"\$")) && (!@strstr($direccion[$i]," ")) &&  (!@strstr($remitente[$i],"'")) && (!@strstr($remitente[$i],"\"")) && (!@strstr($remitente[$i],"\\")) && (!@strstr($remitente[$i],"\$")) && (!@strstr($remitente[$i]," "))) {
     if ((@
substr_count($direccion[$i],".")>= 1) && (@substr_count($remitente[$i],".")>= 1)){
          
$term = @substr(@strrchr ($direccion[$i], '.'),1);
            
$term2= @substr(@strrchr ($remitente[$i], '.'),1);
            if (@
strlen($term)>&& @strlen($term)<&& (!@strstr($term,"@"))  &&  @strlen($term2)>&& @strlen($term2)<&& (!@strstr($term2,"@"))){
            
$antes = @substr($direccion[$i],0,@strlen($direccion[$i]) - @strlen($term) - 1);
            
$antes2 = @substr($remitente[$i],0,@strlen($remitente[$i]) - @strlen($term) - 1);
            
$caracter = @substr($antes,@strlen($antes)-1,1);
            
$caracter2= @substr($antes2,@strlen($antes2)-1,1);
             if (
$caracter != "@" && $caracter != "." && $caracter2 !="@" && $caracter2 !="."){
             
$this->comprobartrue;
             }
      }
     }
    }
   }
    }
    
     if(
$this->comprobar){
     return 
$this->comprobar=true;
     }else{
     return 
$this->comprobar=false;
     }
 }else{
   if ((@
strlen($direccion) >= 3) && (@substr_count($direccion,"@") == 1) && (@substr($direccion,0,1) != "@") && (@substr($direccion,@strlen($direccion)-1,1) != "@") && (@strlen($remitente) >= 6) && (@substr_count($remitente,"@") == 1) && (@substr($remitente,0,1) != "@") && (@substr($direccion,@strlen($remitente)-1,1) != "@")){
    if ((!@
strstr($direccion,"'")) && (!@strstr($direccion,"\"")) && (!@strstr($direccion,"\\")) && (!@strstr($direccion,"\$")) && (!@strstr($direccion," ")) &&  (!@strstr($remitente,"'")) && (!@strstr($remitente,"\"")) && (!@strstr($remitente,"\\")) && (!@strstr($remitente,"\$")) && (!@strstr($remitente," "))) {
     if ((@
substr_count($direccion,".")>= 1) && (@substr_count($remitente,".")>= 1)){
          
$term = @substr(@strrchr ($direccion'.'),1);
            
$term2= @substr(@strrchr ($remitente'.'),1);
            if (@
strlen($term)>&& @strlen($term)<&& (!@strstr($term,"@"))  &&  @strlen($term2)>&& @strlen($term2)<&& (!@strstr($term2,"@"))){
            
$antes = @substr($direccion,0,@strlen($direccion) - @strlen($term) - 1);
            
$antes2 = @substr($remitente,0,@strlen($remitente) - @strlen($term) - 1);
            
$caracter = @substr($antes,@strlen($antes)-1,1);
            
$caracter2= @substr($antes2,@strlen($antes2)-1,1);
             if (
$caracter != "@" && $caracter != "." && $caracter2 !="@" && $caracter2 !="."){
             
$this->comprobar=true;
             }
      }
     }
    }
   }
     if(
$this->comprobar){
     return 
$this->comprobar=true;
     }else{
     return 
$this->comprobar=false;
     }
 }
}
//funcion

/**
* Envia el email
*
* Envia el email mediante funcion mail()
* @acces private
*
*/
function enviar()
{
if(!
$this->direcciones || !$this->asunto || !$this->mensaje || !$this->remitente ){
return 
$this->error(3);
}else{
 if(@
is_array($this->direcciones) || @is_array($this->asunto) || @is_array($this->mensaje) || @is_array($this->remitente)){
  for(
$i=0;$i<count($this->direcciones);$i++){
   if(!@
mail($this->direcciones[$i],$this->asunto[$i],$this->mensaje[$i],"FROM : ".$this->remitente[$i]."\r\nReply To: ".$this->remitente[$i]."\r\n")){
    return 
$this->error(4);
   }else{
    return 
$this->enviado=true;
   }
  }
//fin for
    
}else{
      if(!@
mail($this->direcciones,$this->asunto,$this->mensaje,"FROM : ".$this->remitente."\r\nReply To: ".$this->remitente."\r\n")){
    return 
$this->error(4);
    }else{
    return 
$this->enviado=true;
    }
    }
 }        
}    
//funcion

/**
* Devuelve un mensaje de aviso del envio del mail
*
* @acces private
*
* @return string
*/
function enviado()
{
    if(!
$this->enviado){
        return;
    }else{
        if(
$this->enviado){
            return 
"Email(s) enviado";
        }else{
            return 
"Email(s) no enviado";
        }
    }
}
//funcion


function smtp($server,$port,$user="",$pass="")
{
if(!
$this->direcciones || !$this->asunto || !$this->mensaje || !$this->remitente ){
return 
$this->error(3);
}else{
 
$fp=fsockopen($server,$port,&$errn,&$error,30) or ($this->error(5));
 echo 
fgets($fp,1024);
 
fputs($fp,"EHLO 71675615@globalcom\r\n");
 
fgets($fp,1024);
  if(
$user!="" || $pass!=""){
  
$auth="AUTH LOGIN\r\n";
  
fputs($fp,$auth."\r\n") or ($this->error(6));
  
fgets($fp,1024);
  
$user=base64_encode($user);
  
fputs($fp,$user."\r\n") or ($this->error(6));
  
fgets($fp,1024);
  
$pass=base64_encode($pass);
  
fputs($fp,$pass."\r\n") or ($this->error(6));
  
fgets($fp,1024);
  }
    if(@
is_array($this->direcciones) || @is_array($this->asunto) || @is_array($this->mensaje) || @is_array($this->remitente)){
     for (
$i=0;$i<count($this->direcciones);$i++){
      
fputs($fp,"MAIL FROM:".$this->remitente[$i]."\r\n") or ($this->error(6));
      
fgets($fp,1024);
    
    
fputs($fp,"RCPT TO:".$this->direcciones[$i]."\r\n") or ($this->error(6));
    
fgets($fp,1024);

    
fputs($fp,"DATA\r\n") or ($this->error(6));
    
fgets($fp,1024);

    
fputs($fp,"SUBJECT:".$this->asunto[$i]."\r\n.\r\n") or ($this->error(6));
    
fgets($fp,1024);

    
fputs($fp,$this->mensaje[$i]."\r\n.\r\n") or ($this->error(6));
    
fgets($fp,1024);
     }    
    }else{
  
fputs($fp,"MAIL FROM:".$this->remitente."\r\n") or ($this->error(6));
  
fgets($fp,1024);
  
fputs($fp,"RCPT TO:".$this->direcciones."\r\n") or ($this->error(6));
  
fgets($fp,1024);
  
fputs($fp,"DATA\r\n") or ($this->error(6));
  
fgets($fp,1024);
  
fputs($fp,"SUBJECT:".$this->asunto."\r\n.\r\n") or ($this->error(6));
  
fgets($fp,1024);
  
fputs($fp,$this->mensaje."\r\n.\r\n") or ($this->error(6));
  
fgets($fp,1024);
  }
 
fputs($fp,"QUIT\r\n") or ($this->error(6));
 
fgets($fp,1024);
 
fclose($fp) or ($this->error(7));
}
}
//funcion

/***   FIN CLASE ***/
}
?>
saludos
__________________
3w.valenciadjs.com
3w.laislatv.com
  #3 (permalink)  
Antiguo 12/12/2003, 00:18
Avatar de nuevo  
Fecha de Ingreso: mayo-2003
Ubicación: Spain
Mensajes: 2.009
Antigüedad: 20 años, 11 meses
Puntos: 2
Código PHP:
<?php
/*************** Envio simple via funcion mail()**************************/
$a      "Asunto";
$d      "[email protected]";
$m      "Mensaje";
$r      "[email protected]";
$mail   = new email($a,$d,$m,$r);
$mail->enviar();
echo 
$mail->errores();//Si exisiten errores los mostrara
echo $mail->enviado();//Muestra un mensaje al enviar el mail


/*************** Envio multiple via funcion mail()**************************/
$a      = array("Asunto","Asunto2");
$d      = array("[email protected]","[email protected]");
$m      = array("Mensaje","Mensaje2");
$r      = array("[email protected]","[email protected]");
$mail   = new email($a,$d,$m,$r);
$mail->enviar();
echo 
$mail->errores();//Si exisiten errores los mostrara
echo $mail->enviado();//Muestra un mensaje al enviar el mail


/*************** Envio simple via sockets    **************************/
$a      "Asunto";
$d      "[email protected]";
$m      "Mensaje";
$r      "[email protected]";
$server "169.254.62.112";//Ip o nombre, o direccion del servidor SMTP
$port   "25";//El puerto a usar
$mail   = new email($a,$d,$m,$r);
$mail->smtp($server,$port);
//$mail->smtp($server,$port); En caso de no existir login
echo $mail->errores();//Si exisiten errores los mostrara
echo $mail->enviado();//Muestra un mensaje al enviar el mail


/*************** Envio multiple via sockets    **************************/
$a      = array("Asunto","Asunto2");
$d      = array("[email protected]","[email protected]");
$m      = array("Mensaje","Mensaje2");
$r      = array("[email protected]","[email protected]");
$server "169.254.62.112";//Ip o nombre, o direccion del servidor SMTP
$port   "25";//El puerto a usar
$mail   = new email($a,$d,$m,$r);
$mail->smtp($server,$port);
//$mail->smtp($server,$port); En caso de no existir login
echo $mail->errores();//Si exisiten errores los mostrara
echo $mail->enviado();//Muestra un mensaje al enviar el mail

?>
__________________
3w.valenciadjs.com
3w.laislatv.com
  #4 (permalink)  
Antiguo 12/12/2003, 00:27
 
Fecha de Ingreso: septiembre-2003
Mensajes: 248
Antigüedad: 20 años, 7 meses
Puntos: 2
gracias, lo probaré
__________________
Jose A
  #5 (permalink)  
Antiguo 12/12/2003, 20:22
 
Fecha de Ingreso: septiembre-2003
Mensajes: 248
Antigüedad: 20 años, 7 meses
Puntos: 2
sigue sin llegar
__________________
Jose A
  #6 (permalink)  
Antiguo 12/12/2003, 23:04
Avatar de nuevo  
Fecha de Ingreso: mayo-2003
Ubicación: Spain
Mensajes: 2.009
Antigüedad: 20 años, 11 meses
Puntos: 2
y la classe no te da algun error?
__________________
3w.valenciadjs.com
3w.laislatv.com
  #7 (permalink)  
Antiguo 12/12/2003, 23:52
 
Fecha de Ingreso: septiembre-2003
Mensajes: 248
Antigüedad: 20 años, 7 meses
Puntos: 2
Hola nuevo, gracias por tus respuestas, el problema es que tu clase es para enviar email con formato texto y yo necesito enviar con formato html, el email si llega pero no carga las imagenes a las que le hago referencia
gracias y saludos
__________________
Jose A
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 00:23.