Salve amici!
Ho questi due script per creare un form mail con allegato...
form.html :
<form action="invio.php" method="post" enctype="multipart/form-data" onsubmit="">
<input type="hidden" name="destinatario" value="info@miosito.it">
<table align="center" width="600" cellpadding="2" cellspacing="2">
<tr>
<td>Nome *</td>
<td><input type="text" name="nome" id="nome" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Cognome *</td>
<td><input type="text" name="cognome" id="cognome" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Oggetto</td>
<td><input name="oggetto" type="text" id="oggetto" value="oggetto" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Mail *</td>
<td><input type="text" name="mail" id="mail" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Città *</td>
<td><input type="text" name="città" id="citta" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Telefono *</td>
<td><input type="text" name="telefono" id="telefono" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Codice fiscale *</td>
<td><input type="text" name="codice_fiscale" id="codice_fiscale" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>P iva *</td>
<td><input type="text" name="p_iva" id="p_iva" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Allegato *
visura camerale (pdf) </td>
<td><input type="file" name="allegato" id="allegato" /></td>
</tr>
</table>
<div align="center">
<input type="submit" value="Invia dati" />
</div>
</form>
invio.php :
<?php
$destinatario = $_POST['destinatario'];
$nome=$_POST['nome'];
$cognome=$_POST['cognome'];
$oggetto=$_POST['oggetto'];
$mail=$_POST['mail'];
$citta=$_POST['citta'];
$telefono=$_POST['telefono'];
$codice_fiscale=$_POST['codice_fiscale'];
$p_iva=$_POST['p_iva'];
$messaggio='
Nome :
'.$nome.'
Cognome :
'.$cognome.'
Oggetto :
'.$oggetto.'
Mail :
'.$mail.'
Città :
'.$citta.'
Telefono :
'.$telefono.'
Codice Fiscale :
'.$codice_fiscale.'
p_iva :
'.$p_iva.'
';
$allegato = $_FILES['allegato']['tmp_name'];
$allegato_type = $_FILES['allegato']['type'];
$allegato_name = $_FILES['allegato']['name'];
$headers = "From: " . $mail;
$msg = "";
if (is_uploaded_file($allegato))
{
$file = fopen($allegato,'rb');
$data = fread($file, filesize($allegato));
fclose($file);
$data = chunk_split(base64_encode($data));
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
$msg .= "This is a multi-part message in MIME format.\n\n";
$msg .= "--{$mime_boundary}\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $messaggio . "\n\n";
$msg .= "--{$mime_boundary}\n";
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$allegato_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";
$msg .= "--{$mime_boundary}--\n";
}
else
{
echo "
Errore!</p>";
}
if (mail($destinatario, $oggetto, $msg, $headers))
{
echo "
Mail inviata con successo!</p>";
}else{
echo "
Errore!</p>";
}
Come faccio a rendere obbligatori tutti i campi ?Vi prego aiutatemi?