Salve tutti, sono nuovo del forum e vi faccio i miei complimenti per l'organizzazione e il supporto che fornite.
Vi scrivo perchè ho un problema che non riesco a risolvere. Sto cercando un form che permetta agli utenti del mio sito di mandarmi anche allegati oltre che ai soliti campi testo.
Ne ho trovato uno su Mr.WebMaster ma quando faccio le modifche per adattarlo alle mie esigenze non funziona più, oppure non riesce a mandarmi tutti i campi compilati nell'html in quanto l'invio è diretto dal file php.
Non so se sono stato molto chiaro, quindi vi posto i due file , magari qualcuno di voi potrebbe risolvermi il problema:
Questo è il file HTML, potete dargli il nome che volete
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Modulo d'iscrizione</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="443" height="582" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="443" height="582">
<form action="formmail.php" method="POST" enctype="multipart/form-data">
<p align="center"><strong><font size="3" face="Arial, Helvetica, sans-serif">iscrizione</font></strong></p>
<p>
<input type="hidden" name="destinatario" value="[EMAIL="[email protected]"][email protected][/EMAIL]">
</p>
<table width="443" height="506" border="1" align="center" bordercolor="#333333">
<tr>
<td width="157"><strong>Nome Utente: </strong></td>
<td width="270"><input name="nomeutente" type="text" value="" size="45" /></td>
</tr>
<tr>
<td><strong>Nome: </strong></td>
<td><input name="nome" type="text" value="" size="45" /></td>
</tr>
<tr>
<td><strong>Cognome: </strong></td>
<td><input name="cognome" type="text" value="" size="45" /></td>
</tr>
<tr>
<td><strong>Indirizzo E-Mail: </strong></td>
<td><input name="mittente" type="text" value="" size="45" /></td>
</tr>
<tr>
<td><strong>Oggetto:</strong></td>
<td><div align="center"><strong><font color="#0000FF" size="2" face="Arial, Helvetica, sans-serif">iscrizione</font></strong></div></td>
</tr>
<tr>
<td><strong>Breve Descrizione<br>
</strong></td>
<td><textarea name="descrizione" cols="34"></textarea></td>
</tr>
<tr>
<td><strong>Allega file: </strong></td>
<td><input name="allegato" type="file" size="33" /></td>
</tr>
<tr>
<td height="112"><strong>Regolamento: </strong></td>
<td> <textarea name=t06 rows=8 readonly wrap=off cols=34>prova</textarea>
<p>
<input type="radio" name="accetto" value="radiobutton">
Accetto</p></td>
</tr>
<tr>
<td height="63" colspan="2">
<center>
<p>
<input name="submit" type="submit" value="Invia" />
<input type="reset" name="Reset" value="Cancella">
</p>
<p><INPUT TYPE="button" VALUE="Annulla Iscrizione" NAME="B4"
onClick="window.close()"></p>
</center></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Questo invece è il file php che permette l'invio dell'allegato e dei dati inseriti nel form html e penso sia proprio questo che non funziona in quando mi da errore. Il file deve essere nominato formmail.php
[LEFT]<?php
// Recupero il valore dei campi del form
$nomeutente = $_POST['nomeutente'];
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$mittente = $_POST['mittente'];
$descrizione = $_POST['mittente'];
$accetto = $_POST['accetto'];
$nonaccetto = $_POST['nonaccetto'];[/LEFT]
[LEFT]// Valorizzo le variabili relative all'allegato
$allegato = $_FILES['allegato']['tmp_name'];
$allegato_type = $_FILES['allegato']['type'];
$allegato_name = $_FILES['allegato']['name'];[/LEFT]
[LEFT]// Creo 2 variabili che riempirò più avanti...
$headers = "From: " . $mittente;
$msg = "";[/LEFT]
[LEFT]// 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);[/LEFT]
[LEFT] // Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));[/LEFT]
[LEFT] // 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";[/LEFT]
[LEFT] // Aggiungo le intestazioni necessarie per l'allegato
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";[/LEFT]
[LEFT] // Definisco il tipo di messaggio (MIME/multi-part)
$msg .= "This is a multi-part message in MIME format.\n\n";[/LEFT]
[LEFT] // Metto il separatore
$msg .= "--{$mime_boundary}\n";[/LEFT]
[LEFT] // Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $descrizione . "\n\n";[/LEFT]
[LEFT] // Metto il separatore
$msg .= "--{$mime_boundary}\n";[/LEFT]
[LEFT] // Aggiungo l'allegato al messaggio
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$allegato_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";[/LEFT]
[LEFT] // chiudo con il separatore
$msg .= "--{$mime_boundary}--\n";
}
else
{
$msg = $messaggio;
}[/LEFT]
[LEFT]// Invio la mail
if (mail($nomeutente, $nome, $cognome, $mittente, $accetto, $nonaccetto, $msg, $headers))
{
echo "<p>Mail inviata con successo!</p>";
}else{
echo "<p>Errore!</p>";
}
?>[/LEFT]
Se qualcuno di voi riuscisse a darmi una mano per risolvere il problema gli sarai immensamente grato. Grazia e tutti in anticipo.