Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/12/2005, 13:19
tamahome
Usuario no validado
 
Fecha de Ingreso: agosto-2004
Mensajes: 74
Antigüedad: 19 años, 8 meses
Puntos: 0
PHPMailer adjuntos segun opcion

Ahora de nuevo me envia el mail, pero no adjunta el archivo. envio el codigo completo para ver donde puedo tener el fallo

Gracias por tu atencion

Código PHP:
<?
   
//Es necesario que al menos halla una dirección de destino
   
$error="";

   if (
$enviar) {
      if ((!
$email1) && (!$email2)) {
    
$error.="Debe indicar al menos una dirección de destino";
      }
   }
    
   if (
$enviar && !$error) {

      
//creamos un array que estará formado por las direcciones de destino
      
if ($email1) {
    
$direcciones["direccion1"]=$email1;
      }
      if (
$email2) {
    
$direcciones["direccion2"]=$email2;
      }

      
//pasamos a enviar el correo

      // primero hay que incluir la clase phpmailer para poder instanciar 
      //un objeto de la misma
      
require "includes/class.phpmailer.php";

      
//instanciamos un objeto de la clase phpmailer al que llamamos 
      //por ejemplo mail
      
$mail = new phpmailer();

      
//Definimos las propiedades y llamamos a los métodos 
      //correspondientes del objeto mail

      //Con PluginDir le indicamos a la clase phpmailer donde se 
      //encuentra la clase smtp que como he comentado al principio de 
      //este ejemplo va a estar en el subdirectorio includes
      
$mail->PluginDir "includes/";

      
//Con la propiedad Mailer le indicamos que vamos a usar un 
      //servidor smtp                            
      
$mail->Mailer "smtp";

      
//Asignamos a Host el nombre de nuestro servidor smtp
      
$mail->Host "mail.dominio.com";
      
      
//Le indicamos que el servidor smtp requiere autenticación
      
$mail->SMTPAuth true;

      
//Le decimos cual es nuestro nombre de usuario y password
      
$mail->Username "[email protected]";
      
$mail->Password "xxxxxxxxxxxxx";
      
      
//Indicamos cual es nuestra dirección de correo y el nombre que 
      //queremos que vea el usuario que lee nuestro correo
      
$mail->From "[email protected]";

      
$mail->FromName "Mi nombre";

      
//Asignamos asunto y cuerpo del mensaje
      //El cuerpo del mensaje lo ponemos en formato html, haciendo 
      //que se vea en negrita
      
$mail->Subject "Informacion Solicitada a mi empresa";
      
$mail->Body "<b>Señores aqui tienen la informacion que nos han solicitado</b>";

      
//Definimos AltBody por si el destinatario del correo no admite 
      //email con formato html
      
$mail->AltBody ="Mensaje de prueba mandado con phpmailer en formato texto";

      
//el valor por defecto 10 de Timeout es un poco escaso dado que voy a usar 
      //una cuenta gratuita y voy a usar attachments, por tanto lo pongo a 120  
      
$mail->Timeout=20;

      
//Indicamos el fichero a adjuntar si el usuario seleccionó uno en el formulario
       
if ($_POST['info1']=="ON")  { 
     
$mail->AddAttachment(documentos/archivo.pdf); 

      
      
//Indicamos cuales son las direcciones de destino del correo y enviamos 
      //los mensajes
      
reset($direcciones);
      while (list(
$clave$valor)=each($direcciones)) {
    
$mail->AddAddress($valor);

    
//se envia el mensaje, si no ha habido problemas la variable $success 
    //tendra el valor true
    
$exito $mail->Send();

    
//Si el mensaje no ha podido ser enviado se realizaran 4 intentos mas 
    //como mucho para intentar enviar el mensaje, cada intento se hara 5 s
    //segundos despues del anterior, para ello se usa la funcion sleep
     
$intentos=1
       while((!
$exito)&&($intentos<5)&&($mail->ErrorInfo!="SMTP Error: Data not accepted")){
       
sleep(5);
            
//echo $mail->ErrorInfo;
            
$exito $mail->Send();
            
$intentos=$intentos+1;                
       }

    
//La clase phpmailer tiene un pequeño bug y es que cuando envia un mail con
    //attachment la variable ErrorInfo adquiere el valor Data not accepted, dicho 
    //valor no debe confundirnos ya que el mensaje ha sido enviado correctamente
    
if ($mail->ErrorInfo=="SMTP Error: Data not accepted") {
       
$exito=true;
        }
        
    if(!
$exito)
    {
       echo 
"Problemas enviando correo electrónico a ".$valor;
       echo 
"<br>".$mail->ErrorInfo;    
    }
    else
    {
       
//Mostramos un mensaje indicando las direccion de 
       //destino y fichero  adjunto enviado en el mensaje    
       
$mensaje="<p>Has enviado un mensaje a:<br>";
       
$mensaje.=$valor." ";
              
$mensaje.="</p>";
            echo 
$mensaje;


    }
    
// Borro las direcciones de destino establecidas anteriormente
        
$mail->ClearAddresses();
    
    }
    echo 
"<a href='$PHP_SELF'> VOLVER AL FORMULARIO</a>";
   }
   else {
   
?>

   <HTML>
   <BODY>
   <? If ($error) echo "<font color='red'>$error</font>";?>
   <FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="<?=$PHP_SELF?>">
                <div align="center">
                    <p style="margin-top: 1px; margin-bottom: 1px">
                    <font color="#FF0000" face="Verdana" size="2"><b>.:Envío de 
                    Información</b></font></p>
                    <table border="0" height="241" bgcolor="#E6E6E6" id="table1" width="381" cellpadding="5">
                        <tr>
                            <td height="22" colspan="2" width="118">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">
                            Empresa</font></b></td>
                            <td height="22" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <font size="1" face="Verdana" color="#666666">
                            <input type="text" name="empresa" size="35" style="font-size: 8pt; font-family: Verdana"></font></td>
                        </tr>
                        <tr>
                            <td height="19" colspan="2">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">Envió 
                            Email a</font></b></td>
                            <td height="19" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <font color="#666666">
                            <input type="text" name="email1" size="35" style="font-size: 8pt; font-family: Verdana"></font></td>
                        </tr>
                        <tr>
                            <td height="21" colspan="2">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font face="Verdana" size="1" color="#666666">A la 
                            atención de ...</font></b></td>
                            <td height="21" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <input type="text" name="contacto" size="35" style="font-size: 8pt; font-family: Verdana"></td>
                        </tr>
                        <tr>
                            <td height="142" rowspan="6" width="89">
                            <p style="margin-top: 1px; margin-bottom: 1px">&nbsp;</td>
                            <td height="22" align="center" width="25">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <input type="checkbox" name="info1" value="ON"></td>
                            <td height="22" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">&nbsp;Información 
                            Empresa</font></b></td>
                        </tr>
                        <tr>
                            <td height="22" align="center" width="25">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <font face="Verdana" size="1" color="#666666">
                            <input type="checkbox" name="C2" value="ON" style="font-weight: 700"></font></td>
                            <td height="22" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">&nbsp;Ultima 
                            Revista</font></b></td>
                        </tr>
                        <tr>
                            <td height="22" align="center" width="25">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <font face="Verdana" size="1" color="#666666">
                            <input type="checkbox" name="C3" value="ON" style="font-weight: 700"></font></td>
                            <td height="22" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">&nbsp;Información 
                            Planes de Voz</font></b></td>
                        </tr>
                        <tr>
                            <td height="22" align="center" width="25">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <font face="Verdana" size="1" color="#666666">
                            <input type="checkbox" name="C4" value="ON" style="font-weight: 700"></font></td>
                            <td height="22" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">&nbsp;Información 
                            de Blackberry</font></b></td>
                        </tr>
                        <tr>
                            <td height="22" align="center" width="25">
                            <p style="margin-top: 1px; margin-bottom: 1px">
                            <font face="Verdana" size="1" color="#666666">
                            <input type="checkbox" name="C5" value="ON" style="font-weight: 700"></font></td>
                            <td height="22" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">&nbsp;Información 
                            de Tarjetas 3G </font></b></td>
                        </tr>
                        <tr>
                            <td height="22" align="center" width="25">
                            <p style="margin-top: 1px; margin-bottom: 1px">&nbsp;</td>
                            <td height="22" width="253">
                            <p style="margin-top: 1px; margin-bottom: 1px"><b>
                            <font size="1" face="Verdana" color="#666666">&nbsp;</font></b></td>
                        </tr>
                    </table>
                </div>
                <p align="center" style="margin-top: 1px; margin-bottom: 1px">
                <input type="submit" value="Enviar" name="enviar">&nbsp;&nbsp;
                <input type="reset" value="Restablecer" name="borrar"></p>
            </form>
   </BODY>
   </HTML>
   <?
   
}
?>