Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/10/2015, 05:38
prova17
 
Fecha de Ingreso: octubre-2015
Mensajes: 2
Antigüedad: 8 años, 7 meses
Puntos: 0
Form HTML con envio de 2 files con PHP

Buenos dias,
Tengo un problema que no puedo resolver.
Tengo un form HTML que envia una mail, los datos y los archivios a un correo electronico.

La mail llega correctamente pero los archivos llegan en el correo con nombres extraños como este --> /tmp/phpJih9x2. Sin extensión de archivo.

Alguien me puede ayudar?

Gracias

Aqui el file HTML y PHP.

HTML

Código HTML:
<form id="form1" name="form1" method="post" action="email2.php" enctype="multipart/form-data">

<fieldset>
<legend>Canditatura</legend>
<label>Nome:</label> <input type="text" placeholder="Inserisci il tuo nome" name="nome"  size="30px" required="true"><br>
<label>Cognome:</label> <input type="text" placeholder="Inserisci il tuo cognome" name="cognome" size="30px" required="true"><br>
<label>Email:</label> <input type="email" name="email" placeholder="[email protected]" size="30px" required="true"><br>
<label>Telefono:</label> <input type="tel" name="telefono" placeholder="+39" size="30px"><br>
<label>Allegato 1:</label> <input type="file" id="allegato" name="allegato" required="true"><br>
<label>Allegato 2:</label> <input type="file" id="allegato2" name="allegato2" required="true"><br>

<br><br>
<label class="lprivacy"><input type="checkbox" required="true">Accetto normativa sulla Privacy</label><input type="submit" value="Invia Canditatura" name="submit">
</fieldset>

</form> 
PHP

Código PHP:
<?php
$allegato 
$_FILES['allegato']['tmp_name'];
$allegato_type $_FILES['allegato']['type'];
$allegato_name $_FILES['allegato']['name'];

$allegato2 $_FILES['allegato2']['tmp_name'];
$allegato2_type $_FILES['allegato2']['type'];
$allegato2_name $_FILES['allegato2']['name'];

$email $_POST['email'];
$nome $_POST['nome'];
$cognome $_POST['cognome'];
$telefono $_POST['telefono'];


  
mail_attachment("[email protected]","Subject","Nuova canditatuda da <b>$nome $cognome</b>. <br> Telefono: $telefono <br> Email: $email ",array("$allegato","$allegato2"));
  function 
mail_attachment($to$subject$message$files) {
      
$headers "From: [email protected]";
      
$semi_rand md5(time());
      
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
      
$headers .= "\nMIME-Version: 1.0\n" "Content-Type: multipart/mixed;\n" " boundary=\"{$mime_boundary}\"";

      
$message "This is a multi-part message in MIME format.\n\n" "--{$mime_boundary}\n" "Content-Type: text/html; charset=\"iso-8859-1\"\n" "Content-Transfer-Encoding: 7bit\n\n" $message "\n\n";
      
$message .= "--{$mime_boundary}\n";


      foreach (
$files as $file) {

        
$filename end(explode("/",$file));

        
$data file_get_contents($file);

        
$data chunk_split(base64_encode($data));

        
$message .= "Content-Type: {\"application/octet-stream\"};\n" " name=\"$file\"\n" .
          
"Content-Disposition: attachment;\n" " filename=\"$file\"\n" .
          
"Content-Transfer-Encoding: base64\n\n" $data "\n\n";
        
$message .= "--{$mime_boundary}\n";
      }
        echo (@
mail($to$subject$message$headers)) ? "<p>Messaggio spedito correttamente a $to!</p>" "<p>ERRORE! Messaggio non spedito a $to!</p>";
  } 
// mail-attachment

?>