Ciao a tutti, ho realizzato questo form
<form action="mail.php" method="post" ENCTYPE="multipart/form-data">
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left">
<span class="c2">Dati richiedente</span>
</td></tr>
</table>
<table width="800" border="0" cellpadding="2" cellspacing="0">
<tr>
<td align="left" width="200"><span class="c2">Ragione Sociale Azienda</span></td>
<td align="left" width="200"><input name="ragione_sociale" type="text" size="25"></td>
<td align="left" width="200"><span class="c2">Tipo Azienda</span></td>
<td align="left" width="200">
<select name="tipo_azienda">
<option value="privato" selected="selected">Privato </option>
<option value="Azienda">Azienda </option>
<option value="Ente">Ente </option>
<option value="banca">Banca </option>
<option value="assicurazione">Assicurazione </option>
<option value="Impresa">Impresa </option>
<option value="Altro">Altro </option>
</select>
</fieldset></td>
</tr>
<tr>
<td align="left" width="200"><span class="c2">Nome e Cognome</span></td>
<td align="left" width="200"><input name="nome_mittente" type="text" size="25"></td>
<td align="left" width="200"></td>
<td align="left" width="200"></td>
</tr>
<tr>
<td align="left" width="200"><span class="c2">Via</span></td>
<td align="left" width="200"><input name="via_mittente" type="text" size="25"></td>
<td align="left" width="200"><span class="c2">Città</span></td>
<td align="left" width="200"><input name="citta_mittente" type="text" size="25"></td>
</tr>
<tr>
<td align="left" width="200"><span class="c2">Cap</span></td>
<td align="left" width="200"><input type="text" name="cap_mittente" size="25"></td>
<td align="left" width="200"><span class="c2">Provincia</span></td>
<td align="left" width="200"><input type="text" name="provincia_mittente" size="25"></td>
</tr>
<tr>
<td align="left" width="200"><span class="c2">Telefono</span></td>
<td align="left" width="200"><input type="text" name="telefono_mittente" size="25"></td>
<td align="left" width="200"><span class="c2">Fax</span></td>
<td align="left" width="200"><input type="text" name="fax_mittente" size="25"></td>
</tr>
<tr>
<td align="left" width="200"><span class="c2">E-mail</span></td>
<td align="left" width="200"><input type="text" name="email_mittente" size="25"></td>
<td align="left" width="200"><span class="c2">C.F. o P.Iva</span></td>
<td align="left" width="200"><input type="text" name="codfiscale_mittente" size="25"></td>
</tr>
</table>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left">
<span class="c2">Tipo di intervento</span>
</td></tr>
</table>
<table width="800" border="0" cellpadding="2" cellspacing="0">
<tr><td width="200" valign="top"><span class="c2"></td>
<td width="600"><span class="c2"><input type="radio" name="tipo_intervento" value="ordinario">Ordinario</span>
<span class="c2"><input type="radio" name="tipo_intervento" value="urgente">Urgente</span>
</td></tr>
</table>
<table width="800" border="0" cellpadding="2" cellspacing="0">
<tr><td width="200" valign="top"><span class="c2">Oggetto della consulenza</span></td>
<td width="600">
<input type="hidden" name="oggetto_email" value="perizieonline.com">
<textarea name="testo_email" rows="5" cols="70">
</textarea>
</td></tr>
</table>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left">
<span class="c2">Luogo di intervento</span>
</td></tr>
</table>
<table width="800" border="0" cellpadding="2" cellspacing="0">
<tr>
<td align="left" width="200"><span class="c2">Via</span></td>
<td align="left" width="200"><input type="text" name="via_intervento" size="25"></td>
<td align="left" width="200"><span class="c2">Città</span></td>
<td align="left" width="200"><input type="text" name="citta_intervento" size="25"></td>
</tr>
<tr>
<td align="left" width="200"><span class="c2">Cap</span></td>
<td align="left" width="200"><input type="text" name="cap_intervento" size="25"></td>
<td align="left" width="200"><span class="c2">Provincia</span></td>
<td align="left" width="200"><input type="text" name="provincia_intervento" size="25"></td>
</tr>
<tr>
<td align="left" width="200"><span class="c2">Persona di contatto</span></td>
<td align="left" width="200"><input type="text" name="persona_contatto" size="25"></td>
<td align="left" width="200"><span class="c2">Recapito telefonico</span></td>
<td align="left" width="200"><input type="text" name="recapito_contatto" size="25"></td>
</tr>
</table>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left"><span class="c2">Documentazione allegata</span>
</td></tr>
</table>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr><td width="200" valign="top" align="right"></td>
<td width="600"><input name="allegato" type="file" size="50"></td>
</tr>
</tr>
</table>
<table width="800" border="0" cellpadding="2" cellspacing="0">
<tr><td width="200" valign="top" align="left"><span class="c2">Note</span></td>
<td width="600" align="left">
<textarea name="note" rows="5" cols="70">
</textarea>
</td></tr>
</table>
<table width="800" border="0" cellpadding="2" cellspacing="0">
<tr><td width="200" align="left"><span class="c2">Come volete esser
contattati?</span></td>
<td width="600" align="left">
<span class="c2"><input type="radio" name="tipo_contatto" value="telefono">Telefono</span>
<span class="c2"><input type="radio" name="tipo_contatto" value="mail">Mail</span>
</td></tr>
</table>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<input type="reset" value="Cancella tutto"><input type="submit" value="INVIA RICHIESTA">
<input type="hidden" name="email_destinatario" value="info@perizieonline.com">
<input type="hidden" name="nome_destinatario" value="perizieonline.com">
</td>
</tr>
</form>
che rimanda a questo script php
<?php
// Recupero il valore dei campi del form
$nome_destinatario = $_POST['nome_destinatario'];
$nome_mittente = $_POST['nome_mittente'];
$oggetto_email = $_POST['oggetto_email'];
$testo_email = $_POST['testo_email'];
$email_destinatario = $_POST['email_destinatario'];
$ragione_sociale = $_POST['ragione_sociale'];
$tipo_azienda = $_POST['tipo_azienda'];
$nome_mittente = $_POST['nome_mittente'];
$via_mittente = $_POST['via_mittente'];
$citta_mittente = $_POST['citta_mittente'];
$cap_mittente = $_POST['cap_mittente'];
$provincia_mittente = $_POST['provincia_mittente'];
$telefono_mittente = $_POST['telefono_mittente'];
$fax_mittente = $_POST['fax_mittente'];
$email_mittente = $_POST['email_mittente'];
$codfiscale_mittente = $_POST['codfiscale_mittente'];
$tipo_intervento = $_POST['tipo_intervento'];
$testo_email = $_POST['testo_email'];
$via_intervento = $_POST['via_intervento'];
$citta_intervento = $_POST['citta_intervento'];
$cap_intervento = $_POST['cap_intervento'];
$provincia_intervento = $_POST['provincia_intervento'];
$persona_contatto = $_POST['persona_contatto'];
$recapito_contatto = $_POST['recapito_contatto'];
$note = $_POST['note'];
$tipo_contatto = $_POST['tipo_contatto'];
$oggetto_email = $_POST['oggetto_email'];
// Valorizzo le variabili relative all'allegato
$allegato = $_FILES['allegato']['tmp_name'];
$allegato_type = $_FILES['allegato']['type'];
$allegato_name = $_FILES['allegato']['name'];
// Creo 2 variabili che riempirò più avanti...
$headers = "From: " . $nome_mittente;
$testo = "";
// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($allegato))
{
// Apro e leggo il file allegato
$file = fopen($allegato,'rb');
$data = fread($file, filesize($allegato));
fclose($file);
// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));
// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
// Definisco il tipo di messaggio (MIME/multi-part)
$testo .= "This is a multi-part message in MIME format.\n\n";
// Metto il separatore
$testo .= "--{$mime_boundary}\n";
// Questa è la parte "testuale" del messaggio
$testo .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$testo .= "Content-Transfer-Encoding: 7bit\n\n";
$testo .= "Email dal form di PERIZIEONLINE\n\n";
$testo .= "\n\n";
$testo .= "RAGIONE SOCIALE\n\n";
$testo .= $ragione_sociale . "\n\n";
$testo .= "TIPO AZIENDA\n\n";
$testo .= $tipo_azienda . "\n\n";
$testo .= "MITTENTE\n\n";
$testo .= $nome_mittente . "\n\n";
$testo .= $email_mittente . "\n\n";
$testo .= $codfiscale_mittente . "\n\n";
$testo .= "INDIRIZZO MITTENTE \n\n";
$testo .= $via_mittente . "\n\n";
$testo .= $citta_mittente . "\n\n";
$testo .= $cap_mittente . "\n\n";
$testo .= $provincia_mittente . "\n\n";
$testo .= "RECAPITO MITTENTE\n\n";
$testo .= $telefono_mittente . "\n\n";
$testo .= $fax_mittente . "\n\n";
$testo .= "TIPO DI INTERVENTO\n\n";
$testo .= $tipo_intervento . "\n\n";
$testo .= "DESCRIZIONE OGGETTO DELLA CONSULENZA\n\n";
$testo .= $testo_email . "\n\n";
$testo .= "INDIRIZZO INTERVENTO\n\n";
$testo .= $via_intervento . "\n\n";
$testo .= $citta_intervento . "\n\n";
$testo .= $cap_intervento . "\n\n";
$testo .= $provincia_intervento . "\n\n";
$testo .= "PERSONA DI CONTATTO\n\n";
$testo .= $persona_contatto . "\n\n";
$testo .= $recapito_contatto . "\n\n";
$testo .= $tipo_contatto . "\n\n";
$testo .= $email_mittente . "\n\n";
$testo .= "NOTE\n\n";
$testo .= $note . "\n\n";
// Metto il separatore
$testo .= "--{$mime_boundary}\n";
// Aggiungo l'allegato al messaggio
$testo .= "Content-Disposition: attachment;\n";
$testo .= " filename=\"{$allegato_name}\"\n";
$testo .= "Content-Transfer-Encoding: base64\n\n";
$testo .= $data . "\n\n";
// chiudo con il separatore
$testo .= "--{$mime_boundary}--\n";
}
else
{
$testo .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$testo .= "Content-Transfer-Encoding: 7bit\n\n";
$testo .= "Email dal form di PERIZIEONLINE\n\n";
$testo .= "\n\n";
$testo .= "RAGIONE SOCIALE\n\n";
$testo .= $ragione_sociale . "\n\n";
$testo .= "TIPO AZIENDA\n\n";
$testo .= $tipo_azienda . "\n\n";
$testo .= "MITTENTE\n\n";
$testo .= $nome_mittente . "\n\n";
$testo .= $email_mittente . "\n\n";
$testo .= $codfiscale_mittente . "\n\n";
$testo .= "INDIRIZZO MITTENTE \n\n";
$testo .= $via_mittente . "\n\n";
$testo .= $citta_mittente . "\n\n";
$testo .= $cap_mittente . "\n\n";
$testo .= $provincia_mittente . "\n\n";
$testo .= "RECAPITO MITTENTE\n\n";
$testo .= $telefono_mittente . "\n\n";
$testo .= $fax_mittente . "\n\n";
$testo .= "TIPO DI INTERVENTO\n\n";
$testo .= $tipo_intervento . "\n\n";
$testo .= "DESCRIZIONE OGGETTO DELLA CONSULENZA\n\n";
$testo .= $testo_email . "\n\n";
$testo .= "INDIRIZZO INTERVENTO\n\n";
$testo .= $via_intervento . "\n\n";
$testo .= $citta_intervento . "\n\n";
$testo .= $cap_intervento . "\n\n";
$testo .= $provincia_intervento . "\n\n";
$testo .= "PERSONA DI CONTATTO\n\n";
$testo .= $persona_contatto . "\n\n";
$testo .= $recapito_contatto . "\n\n";
$testo .= $tipo_contatto . "\n\n";
$testo .= $email_mittente . "\n\n";
$testo .= "NOTE\n\n";
$testo .= $note . "\n\n";
}
// Invio la mail
if (mail($email_destinatario, $email_mittente, $testo, $headers))
{
echo "<script>location='http://www.perizieonline.com/grazie.html';</script>";
}else{
echo "<center>
Errore: La Mail non è stata inviata!</p></center>";
}
?>
il tutto funziona correttamente, il problema è che ora vorrei dare, per chi lo desiderasse, la possibilità di caricare più di un allegato, quali sono le possibili soluzioni e il relativo codice? E' possibile lasciare una sola casella di inserimento del file e caricarli da lì? o devo per forza fare più caselle (ad es 5) e ognuno carica i file che desidera? questa seconda soluzione non mi piace molto pero'... Grazie mille in anticipo!!!