Salve a tutti...
Ho bisogno del vostro aiuto...
Siccome sto facendo un FORM con i campi e un allegato file, com'è il codice d'invio e-mail con allegato?
Non è così? Però, quando ricevo, non si vede un file allegato, ma decifra una marea di codici...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PREVENTIVO ON-LINE</title>
<link rel="stylesheet" href="stile_flash.css">
</head>
<body>
<?php
$confirm = $_REQUEST['confirm'];
if($confirm)
{
// Recupero il valore dei campi del form
$destinatario = $_POST['destinatario'];
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$marca = $_POST['marca'];
$cilindrata = $_POST['cilindrata'];
$danno = $_POST['danno'];
$to = "aaa@aaa.it";
$subject = "Preventivo On-line";
// Valorizzo le variabili relative all'allegato
$allegato = $_FILES['allegato']['tmp_name'];
$allegato_type = $_FILES['allegato']['type'];
$allegato_name = $_FILES['allegato']['name'];
// 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";
$message = "--{$mime_boundary}\n";
$message .= "
PREVENTIVO ON-LINE
Il cliente $nome $cognome dell'e-mail $destinatario, ti ha scritto:
MARCA E MODELLO VEICOLO = $marca
CILINDRATA = $cilindrata
DESCRIZIONE DEL DANNO = $danno
ALLEGATO FOTO = $allegato";
// Aggiungo l'allegato al messaggio
$message .= "Content-Disposition: attachment;\n";
$message .= " filename=\"{$allegato_name}\"\n";
$message .= "Content-Transfer-Encoding: binary\n\n";
$message .= $data . "\n\n";
$message .= "--{$mime_boundary}--\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/octet-stream ; charset=iso-8859-1\n";
$headers .= " boundary=\"{$mime_boundary}\"";
$headers .= "From: $nome $cognome < $email >\n";
// Invio la mail
if (mail($to, $subject, $message, $headers))
{
echo "<table width=\"90%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_bianco_sinistro\" align=\"center\" />
<tr>
<td bgcolor=\"FFFF99\"><table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_gr\" align=\"center\" />
<tr>
<td></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
Grazie per averci inviato la tua richiesta.
Ti risponderemo al più presto possibile.
Buona giornata!
LA MADONNINA ROMA
<img src=\"images/car2.gif\" border=\"0\" />
</p></td>
</tr>
</table>";
} else {
echo "
Errore!</p>";
}
} else {
echo"<form name=\"preventivo\" method=\"post\" enctype=\"multipart/form-data\" action=\"{$_SERVER['PHP_SELF']}?confirm=1\">
<input type=\"hidden\" name=\"destinatario\" value=\"aa@aaa.it\">
<table width=\"90%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_bianco_sinistro\" align=\"center\" />
<tr>
<td bgcolor=\"FFFF99\"><table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_gr\" align=\"center\" />
<tr>
<td></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">PREVENTIVO ON-LINE
<img src=\"images/car2.gif\" border=\"0\" /></td>
</tr>
<tr>
<td colspan=\"2\">Con il suo lancio in rete, da quest’anno, ti offre anche il preventivo on-line! Inviandoci alcune foto del danno del tuo mezzo, cerchiamo di fornirti un preventivo il più corretto possibile, senza farti muovere di casa.</td>
</tr>
<tr>
<td colspan=\"2\"><hr></td>
</tr>
<tr>
<td>NOME</td>
<td><input type=\"text\" name=\"nome\" /></td>
</tr>
<tr>
<td>COGNOME</td>
<td><input type=\"text\" name=\"cognome\" /></td>
</tr>
<tr>
<td>E-MAIL</td>
<td><input type=\"text\" name=\"mittente\" /></td>
</tr>
<tr>
<td valign=\"top\">MARCA
E MODELLO VEICOLO</td>
<td><textarea cols=\"20\" rows=\"4\" name=\"marca\"></textarea></td>
</tr>
<tr>
<td>CILINDRATA</td>
<td><input type=\"text\" name=\"cilindrata\" /></td>
</tr>
<tr>
<td valign=\"top\">DESCRIZIONE
DEL DANNO</td>
<td><textarea cols=\"20\" rows=\"4\" name=\"danno\"></textarea></td>
</tr>
<tr>
<td>ALLEGA FOTO</td>
<td><input type=\"file\" name=\"allegato\" /></td>
</tr>
<tr>
<td colspan=\"2\"><hr></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\" >Una volta inviati i dati richiesti, ti contatteremo nel più breve tempo possibile.</td>
</tr>
<tr>
<td colspan=\"2\"><hr></td>
</tr>
<tr>
<td align=\"center\"><input type=\"reset\" value=\"Reimposta\" /></td>
<td align=\"center\"><input type=\"submit\" value=\"Invia\" /></td>
</tr>
<tr>
<td colspan=\"2\"></td>
</tr>
</table></td>
</tr>
</table>
</form>";
}
?>
</body>
</html>