Foros del Web » Programando para Internet » PHP »

Problemas con mi envio de correo al migrar de php4 a php5

Estas en el tema de Problemas con mi envio de correo al migrar de php4 a php5 en el foro de PHP en Foros del Web. Buenas tardes, tengo el siguiente codigo para envio de correo con adjuntos y todo me funcionaba perfecto enphp4; pero mi proveedor de hosting migro a ...
  #1 (permalink)  
Antiguo 21/09/2010, 08:16
Avatar de Mirovita  
Fecha de Ingreso: febrero-2005
Ubicación: Caracas-Venezuela
Mensajes: 840
Antigüedad: 19 años, 1 mes
Puntos: 10
Problemas con mi envio de correo al migrar de php4 a php5

Buenas tardes,

tengo el siguiente codigo para envio de correo con adjuntos y todo me funcionaba perfecto enphp4; pero mi proveedor de hosting migro a php y comenzaron las fallas.

actualmente cuando envio elcorreo a gmail me llega perfecto, el problema es cuando lo envio a outlook q me llega distorcionado.. coloco codigo de envio de mail....

Código PHP:
function send_mail($emailaddress$fromaddress$emailsubject$body$attachments=false)
{
  
$eol="\r\n";
  
$mime_boundary='-----=' md5uniqid(rand())); //boundary para dividir los atachhments
  
$htmlalt_mime_boundary $mime_boundary."_htmlalt"//we must define a different MIME boundary for this section for the alternative to work properly in all email clients
 
  # Common Headers
  
$headers .= 'From: Comunicaciones Kentron.com.ve<'.$fromaddress.'>'.$eol;
  
$headers .= 'Reply-To: Comunicaciones Kentron.com.ve<'.$fromaddress.'>'.$eol;
  
$headers .= 'Return-Path: Comunicaciones Kentron.com.ve<'.$fromaddress.'>'.$eol;    // these two to set reply address
  
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
  
$headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters

  # Boundry for marking the split & Multitype Headers
  
$headers .= 'MIME-Version: 1.0'.$eol;

  
$msg "";     
 
  if (
$attachments !== false)
  {
    
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol//declaro en el HEADER esto para que funcionen los atacchments
    
for($i=0$i count($attachments); $i++)
    {
      if (
$attachments[$i]["file"]!='')
      {  
          
//echo "B";
        # File for Attachment
        
$file_name $attachments[$i]["file"];
        
$f_contents=$attachments[$i]["content"];//
        
$f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
        # Attachment
        
$msg .= "--".$mime_boundary.$eol//antes de cada attachment declaro el tipo divisor
        
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
        
$msg .= "Content-Transfer-Encoding: base64".$eol;
        
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol// !! This line needs TWO end of lines !! IMPORTANT !!
        
$msg .= $f_contents.$eol.$eol;       
      }
    }
    
$msg .= "--".$mime_boundary.$eol;///cierre del ultimo de los attachments
  
}
 
# Setup for text OR html -


$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol//abro el tipo alternativo para texto o html
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= strip_tags(str_replace("<br>""\n"$body)).$eol.$eol;

# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body.$eol.$eol;

//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol//cierro todos los alternativos

# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol//SIN ESTA LINEA FUNCIONA BIEN, CON ELLA DA PROBLEMAS.

  # SEND THE EMAIL
  
ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
  
mail($emailaddress$emailsubject$msg$headers);
  
ini_restore(sendmail_from);
  
//termina la funcion send_mail 

y el correo me llega mas o menos asi:

Cita:
Estimado Usuario:

Empresa: xxxx

E-mail: [email protected]

Le informamos que se acaba de registrar exitosamente un incidente bajo el nombre de su empresa.


El número del incidente es: 505897
Fecha:21/09/2010

Producto: SOWEB

Módulo: Agregar

Ventana:

Versión:

Descripción: prueba

Archivos Anexos:


INFORMACIÓN IMPORTANTE DE xxxxx

---------------------------------



---------------------------------

Atentamente

Coordinación de Atención al Cliente.

Sistemas de Información.

http://www.kentron.com.ve

Teléfonos: (58-212) xxx-xxxx, xxx-xxxx, xxx-xxxx

Fax: (58 212) xxx-7xxx

E-mail: [email protected]

-------=b3dc532cca3cf3c362d90eb1d54e3d2c_htmlalt
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<em>Estimado Usuario:</em><br>
Empresa: xxxxxx <br>
E-mail: [email protected] <br><BR>
Le informamos que se acaba de registrar exitosamente un incidente bajo el nombre de su empresa. <br><br>
El número del incidente es: 505897 <BR>
Fecha:21/09/2010<br>
Producto: SOWEB<br>
Módulo: Agregar<br>
Ventana: <br>
Versión: <br>
Descripción: prueba<br>
Archivos Anexos: <br><br>
INFORMACIÓN IMPORTANTE DE xxxx<br>
---------------------------------<br>
<br>
--------------------------------- <br>
Atentamente<br>
Coordinación de Atención al Cliente.<br>
Kentron Sistemas de Información.<br>
http://www.kentron.com.ve<br>
Teléfonos: (58-212) xxx-xxxx, xxx-xxxx, xxx-xxxx<br>
Fax: (58 212) 7xx-xxxx<br>
E-mail: [email protected]

-------=b3dc532cca3cf3c362d90eb1d54e3d2c_htmlalt--
y deberia llegar asi:

Cita:
Estimado Usuario Administrador:
Empresa: xxxxx
E-mail: [email protected]

Le informamos que se acaba de registrar un incidente bajo el número: 502965 y fue registrado por: [email protected]. Con las siguientes especificaciones:

Fecha:21/09/2010
Producto: SOWEB
Módulo: SOWEB
Ventana:
Versión:
Descripción: prueba de gmail
Archivos Anexos:

INFORMACIÓN IMPORTANTE DE xxxx
---------------------------------

---------------------------------
Atentamente
Coordinación de Atención al Cliente.
Sistemas de Información.
http://www.kentron.com.ve
Teléfonos: (58-212) xxx-xxxx, xxx-xxxx, xxx-xxxx
Fax: (58 212) 7xx-xxxx
E-mail: [email protected]

Gracias
__________________
.-._.-. [email protected]._.-.
  #2 (permalink)  
Antiguo 24/09/2010, 14:13
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Problemas con mi envio de correo al migrar de php4 a php5

Antes de continuar comprueba como queda el string que contiene en mensaje antes de enviarse, mira a ver si tiene ese html que te aparece al final.
También has de comprobar los mensajes en otros clientes de correo, la lectura de los mensajes varía bastante de un cliente a otro.
En principio no parece que tenga nada que ver con la versión de PHP.
Para estos casos te recomiendo que utilices PHPMailer y te quites de encima todos estos problemas. La función que estás utilizando la puedes adaptar facilmente y olvidarte de todas estas historias. Además, PHPMailer está actualizada para PHP 5.x.
Espero que te sirva de ayuda, saludos

Etiquetas: correo, envio, migrar
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 15:25.