Ver Mensaje Individual
  #16 (permalink)  
Antiguo 11/11/2014, 07:18
mauritosuarez
 
Fecha de Ingreso: octubre-2014
Ubicación: Buenos Aires
Mensajes: 278
Antigüedad: 9 años, 6 meses
Puntos: 12
Respuesta: Formulario web con archivo adjunto

Hola amigo perdón por la demora, estuve realizando unas modificaciones al script y me a funcionado de maravilla. Te paso el código, solo tienes que modificar el mail de la web y un mail de prueba para que te llegue a tí.

index.php
Código HTML:
Ver original
  1. <form accept-charset="utf-8" action="enviar.php" class="trabaja" enctype="multipart/form-data" id="formulario" method="post">
  2.  
  3. <input type="text" id="nombre" name="nombre" value="Nombre" />
  4. <input type="text" id="apellido" name="apellido" value="Apellidos" />
  5. <input type="text" id="email" name="email" value="e-mail" />
  6. <input type="text" id="telefono" name="telefono" value="Telefono" />
  7. <input type="file" id="filead" name="filead" />
  8. <input type="checkbox" id="condiciones" name="condiciones" />
  9. <input type="submit" value="Enviar Formulario" />
  10.  
  11. </form>

enviar.php
Código PHP:
Ver original
  1. <?php
  2. if ($_POST){
  3.    
  4. // Tomas la informacion del archivo subido.
  5. $partes_ruta = pathinfo($_FILES["filead"]["name"]);
  6.  
  7. // obtenemos el tamaño del archivo subido
  8. $fsize = $_FILES["filead"]["size"];
  9.  
  10. if($partes_ruta['extension'] == "doc" or $partes_ruta['extension'] == "docx" or $partes_ruta['extension'] == "pdf" and $fsize <= 1516165165 )
  11. {
  12.  
  13.     $num = md5(time());
  14.  
  15.     //MAIL BODY
  16.     $body = "
  17.    <html>
  18.    <head>
  19.    <title>Formulario Trabaja con nosotros</title>
  20.    </head>
  21.    <body style='background:#EEE; padding:30px;'>
  22.    <h2 style='color:#767676;'>Trabaja con nosotros</h2>";
  23.  
  24.     $body .= "
  25.    <strong style='color:#0090C6;'>Nombre: </strong>
  26.    <span style='color:#767676;'>" . $_POST["nombre"] . "</span>";
  27.  
  28.     $body .= "
  29.    <strong style='color:#0090C6;'>Apellidos: </strong>
  30.    <span style='color:#767676;'>" . $_POST["apellido"] . "</span>";
  31.  
  32.     $body .= "
  33.    <strong style='color:#0090C6;'>Email: </strong>
  34.    <span style='color:#767676;'>" . $_POST["email"] . "</span>";
  35.  
  36.     $body .= "
  37.    <strong style='color:#0090C6;'>Teléfono: </strong>
  38.    <span style='color:#767676;'>" . $_POST["telefono"] . "</span>";
  39.  
  40.     $body .= "</body></html>";
  41.  
  42.     $_name=$_FILES["filead"]["name"];
  43.     $_type=$_FILES["filead"]["type"];
  44.     $_size=$_FILES["filead"]["size"];
  45.     $_temp=$_FILES["filead"]["tmp_name"];
  46.  
  47.     if( strcmp($_name, "") ) //FILES EXISTS
  48.     {
  49.     $fp = fopen($_temp, "rb");
  50.     $file = fread($fp, $_size);
  51.     $file = chunk_split(base64_encode($file));
  52.  
  53.     // MULTI-HEADERS Content-Type: multipart/mixed and Boundary is mandatory.
  54.     $headers = "From: GME <[email protected]>\r\n"; // Modifica el mail de la web
  55.     $headers .= "MIME-Version: 1.0\r\n";
  56.     $headers .= "Content-Type: multipart/mixed; ";
  57.     $headers .= "boundary=".$num."\r\n";
  58.     $headers .= "--".$num."\n";
  59.  
  60.     // HTML HEADERS
  61.     $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
  62.     $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  63.     $headers .= "".$body."\n";
  64.     $headers .= "--".$num."\n";
  65.  
  66.     // FILES HEADERS
  67.     $headers .= "Content-Type:application/octet-stream ";
  68.     $headers .= "name=\"".$_name."\r\n";
  69.     $headers .= "Content-Transfer-Encoding: base64\r\n";
  70.     $headers .= "Content-Disposition: attachment; ";
  71.     $headers .= "filename=\"".$_name."\r\n\n";
  72.     $headers .= "".$file."\r\n";
  73.     $headers .= "--".$num."--";
  74.  
  75.     }else { //FILES NO EXISTS
  76.  
  77.     // HTML HEADERS
  78.     $headers = "From: GME \r\n";
  79.     $headers .= "MIME-Version: 1.0\r\n";
  80.     $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
  81.     $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  82.     }
  83.  
  84.  
  85.     // SEND MAIL
  86.     mail("[email protected]", "WEB - Trabaja con nosotros" , $body, $headers); // --> Aqui se espesificaran los usuarios.
  87.     //mail("[email protected]", "WEB - Trabaja con nosotros" , "hola", "cabecera");
  88.  
  89.     echo "<div class='ok'>
  90.    <strong>El formulario se ha enviado correctamente.</strong></div>";
  91. } else {
  92.     print "El tipo de documento no es correcto, recuerde solo se permitern .doc - .docx - .pdf"; exit;
  93. }
  94. /*
  95. print $headers; echo "<br>";
  96. print "------------------------------------------------------ <br>";
  97. print $body; exit;*/
  98. }
  99. ?>
__________________
http://www.sp-vision.net

Última edición por mauritosuarez; 11/11/2014 a las 07:24