Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/09/2006, 21:20
Avatar de quitos
quitos
 
Fecha de Ingreso: junio-2004
Mensajes: 119
Antigüedad: 20 años, 9 meses
Puntos: 1
Pregunta E-mail multiparte "mime_boundary"

Que tal saludos a todos, y nuevamente solicitando su ayuda. veran tengo este problama... les voy a poner toda la pagina para que no haya dudas, por favor ayudenme ya me atore demasiado.... y ni idea del error.

Aclaro esto es codigo de varios sitios y noes mio, pero es muy util !!!
Y les doy gracias a los desarrolladores que lo hicieron
Ok comensemos con mi problema....

Código PHP:
<html>
<head>
<title>Envio de correo con Varios archivos adjuntos</title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD']=="POST")
{
  
$to="[email protected]";
  
$subject="E-mail Con Adjuntos";
    
    
// Pone el nombre y el correo de quien lo envia
    // solo ponemos las variables que las va a enviar el formulario
    
$from stripslashes($_POST['Name'])."<".stripslashes($_POST['Email']).">";
    
    
// Guardamos el texto del mensaje
    
$message "Apartado Postal: ".$_POST['Apartado']."\n";
    
$message .= "Colonia: ".$_POST['Colonia']."\n";
    
$message .= "Codigo Postal: ".$_POST['CP']."\n";
    
$message .= "Pais: ".$_POST['Pais']."\n";
    
$message .= "Estado: ".$_POST['Estado']."\n\n"
    
$message .= "Mensaje: ".$_POST['Mensaje'];

    
// generate a random string to be used as the boundary marker
    //$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
    
$semi_rand md5(time());
    
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
    
    
// Valida el acceso del archivo 1
    
if(isset($_FILES))
    {
    if(
$_FILES['filename1']['tmp_name'])
    {
    
$tmp_name1 $_FILES['filename1']['tmp_name'];
    
$type1 $_FILES['filename1']['type'];
    
$name1 $_FILES['filename1']['name'];
    
$size1 $_FILES['filename1']['size'];
    }
    }
    if (
file_exists($tmp_name1))
    {
    if(
is_uploaded_file($tmp_name1))
    {
    
$file1 fopen($tmp_name1,'rb');
    
$data1 fread($file1,filesize($tmp_name1));
    
fclose($file1);
    
$data1 chunk_split(base64_encode($data1));
    }    
    
$headers "From: $from\r\n" .
    
"MIME-Version: 1.0\r\n" .
    
"Content-Type: multipart/mixed;\r\n".
    
" boundary=\"{$mime_boundary}\"";
    
$message "This is a multi-part message in MIME format.\n\n".
    
"--{$mime_boundary}\n" .
    
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
    
"Content-Transfer-Encoding: 7bit\n\n".
    
$message "\n\n";
     
//Inicia el 1
 
$message .= "--{$mime_boundary}\n" .
 
"Content-Type: {$type1};\n" .
 
" name=\"{$name1}\"\n" .
 
"Content-Transfer-Encoding: base64\n\n" .
 
$data1 "\n\n" .
 
"--{$mime_boundary}--\n";
         
 if (@
mail($to$subject$message$headers))
 {
  echo 
"Envio Correcto";
 }
  else
  {
  echo 
"Fallo en el envío";
  }
  }
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
   enctype="multipart/form-data" name="form1">
  <table width="871" border="0" align="center" cellpadding="0" cellspacing="0">
     <tr>
       <td height="30" bordercolor="#FFFFFF" bgcolor="#970000">&nbsp;</td>
     </tr>
     <tr>
       <td><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
         <tr>
           <td width="194" height="30" class="Estilo3">Nombre y Apellido </td>
           <td colspan="2"><span class="Estilo1">
             <input name="Name" type="text" id="Name" size="50">
           </span></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3">Email</td>
           <td colspan="2"><input name="Email" type="text" id="Email" size="30"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3">Apartado Portal</td>
           <td colspan="2"><input name="Apartado" type="text" id="Apartado" size="15"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3"><span class="Estilo1">Colonia</span></td>
           <td colspan="2"><input name="Colonia" type="text" id="Colonia" size="15"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3"><span class="Estilo1">C.P.</span></td>
           <td colspan="2"><input name="CP" type="text" id="CP" size="50"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3"><span class="Estilo1">Pa&iacute;s</span></td>
           <td colspan="2"><input name="Pais" type="text" id="Pais" size="50"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3"><span class="Estilo1">Estado</span></td>
           <td colspan="2"><input name="Estado" type="text" id="Estado" size="50"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3"><span class="Estilo1">Mensaje:</span></td>
           <td colspan="2"><textarea name="Mensaje" cols="50" rows="6" id="Mensaje"></textarea></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3">Subir Archivo 1:</td>
           <td colspan="2"><input name="filename1" type="file" id="filename1"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3">Subir Archivo 2:</td>
           <td colspan="2"><input name="filename2" type="file" id="filename2"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3">Subir Archivo 3:</td>
           <td colspan="2"><input name="filename3" type="file" id="filename3"></td>
         </tr>
         <tr>
           <td height="30" class="Estilo3">Subir Archivo 4:</td>
           <td colspan="2"><input name="filename4" type="file" id="filename4"></td>
         </tr>
         
       </table></td>
     </tr>
     
     <tr>
       <td height="40" valign="middle" bgcolor="#666666"><span class="Estilo3">
         <input type="submit" name="Submit" value="Enviar Datos">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Submit2" value="Limpiar Formulario">
       </span></td>
     </tr>
  </table>
</form>
<p>
  <?php ?>
</p>
</body>
</html>
ese es el original y solo adjunta un archivo sin ningun problema solo se sube al servidor y debe de funcionar, mi problema es que no quiero mandar solo un archivo adjunto, sino, quiero ADJUNTAR MAS, minimo 3, ya le hice estas modificaciones y aun asi no me queda, les muestro, solo el php

Código PHP:
<?php
if ($_SERVER['REQUEST_METHOD']=="POST")
{
    
$to="[email protected]";
        
$subject="E-mail Con Adjuntos";
    
    
// Pone el nombre y el correo de quien lo envia
    // solo ponemos las variables que las va a enviar el formulario
    
$from stripslashes($_POST['Name'])."<".stripslashes($_POST['Email']).">";
    
    
// Guardamos el texto del mensaje
    
$message "Apartado Postal: ".$_POST['Apartado']."\n";
    
$message .= "Colonia: ".$_POST['Colonia']."\n";
    
$message .= "Codigo Postal: ".$_POST['CP']."\n";
    
$message .= "Pais: ".$_POST['Pais']."\n";
    
$message .= "Estado: ".$_POST['Estado']."\n\n"
    
$message .= "Mensaje: ".$_POST['Mensaje'];

    
// aqui hay dos maneras una es la que esta comentada y la que deje 
        // libre, las dos funcionan
    //$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
    
$semi_rand md5(time());
    
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
    
$mime_boundary2 "==Multipart_Boundary_x{$semi_rand}x";
    
    if(isset(
$_FILES))
        {
           if(
$_FILES['filename1']['tmp_name'])
               {
                      
$tmp_name1 $_FILES['filename1']['tmp_name'];
                      
$type1 $_FILES['filename1']['type'];
                      
$name1 $_FILES['filename1']['name'];
                      
$size1 $_FILES['filename1']['size'];
               }
               if(
$_FILES['filename2']['tmp_name'])
               {
                   
$tmp_name2 $_FILES['filename2']['tmp_name'];
                   
$type2 $_FILES['filename2']['type'];
                   
$name2 $_FILES['filename2']['name'];
                   
$size2 $_FILES['filename2']['size'];
           }
    
    }
    if (
file_exists($tmp_name1))
    {
        if(
is_uploaded_file($tmp_name1))
        {
            
$file1 fopen($tmp_name1,'rb');
            
$data1 fread($file1,filesize($tmp_name1));
            
fclose($file1);
            
$data1 chunk_split(base64_encode($data1));
            
        }    
        if(
is_uploaded_file($tmp_name2))
        {
            
$file2 fopen($tmp_name2,'rb');
            
$data2 fread($file2,filesize($tmp_name2));
            
fclose($file2);
            
$data2 chunk_split(base64_encode($data2));
            
        }    
        
        
$headers "From: $from\r\n" .
        
"MIME-Version: 1.0\r\n" .
        
"Content-Type: multipart/mixed;\r\n".
        
" boundary=\"{$mime_boundary}\"";
        
$message "This is a multi-part message in MIME format.\n\n".
        
"--{$mime_boundary}\n" .
        
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
        
"Content-Transfer-Encoding: 7bit\n\n".
        
$message "\n\n";
        
        
//Inicia el 1
        
$message .= "--{$mime_boundary}\n" .
               
"Content-Type: {$type1};\n" .
               
" name=\"{$name1}\"\n" .
               
"Content-Transfer-Encoding: base64\n\n" .
               
$data1 "\n\n" .
               
"--{$mime_boundary}--\n";
         
               
$message .= "--{$mime_boundary2}\n" .
               
"Content-Type: {$type2};\n" .
               
" name=\"{$name2}\"\n" .
               
"Content-Transfer-Encoding: base64\n\n" .
               
$data2 "\n\n" .
               
"--{$mime_boundary2}--\n";
         
        if (@
mail($to$subject$message$headers))
        {
            echo 
"Envio Correcto";
        }
        else
        {
            echo 
"Fallo en el envío";
        }
    }
}
else
{
?>
lo que va del formulario
  <?php ?>
</p>
</body>
</html>
Esto tambien funciona, pero solo me adjunta un solo archivo, como puedo hacer que me adjunte mas de uno???, les agradeceria su super ayuda, de ante mano mil gracias, los que me puedan orientar en el camino del conocimiento...