Codice PHP:
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";
if (mail($destinatario, $oggetto, $msg, $headers))
{
header("Refresh: 5; URL=index.html");
echo "
<p align='center'>Mail inviata con successo !
Sarete contattati al più presto !
Reindirizzamento....</p>";
} else {
echo "Errore";
}
} else {
$destinatario = $_POST['destinatario'];
$nome=$_POST['nome'];
$cognome=$_POST['cognome'];
$oggetto=$_POST['oggetto'];
$mail=$_POST['mail'];
$citta=$_POST['citta'];
$telefono=$_POST['telefono'];
$message=$_POST['message'];
$messaggio="
Nome : $nome
Cognome : $cognome
Oggetto : $oggetto
Mail : $mail
Città : $citta
Telefono : $telefono
Messaggio : $message
";
if (mail($destinatario, $oggetto, $msg, $headers))
{
header("Refresh: 5; URL=index.html");
echo "
<p align='center'>Mail inviata con successo - MA SENZA ALLEGATO - !
Sarete contattati al più presto !
Reindirizzamento....</p>";
} else {
echo "Errore";
}
}