Grazie in anticipo a tutti...

In una cartella del mio sito ho un file .txt che deve essere inviato come allegato alla mail di un utente.

Ho fatto così, ma il messaggio arriva senza allegato... (posto parte del codice che interessa)

<?

$subject = "copia txt";
$attach="d:/inetpub/webs/sitocom/file/cartella/copia.txt";
$boundary = md5(uniqid(microtime()));
$file_name = $_FILES[$attach]["name"];
$file_type = $_FILES[$attach]["type"];
$file_size = $_FILES[$attach]["size"];

// APRO ALLEGATO PER CODIFICARLO
$file = @fopen($attach, "r");
$contents = @fread($file, $file_size);
$encoded_attach = chunk_split(base64_encode($contents));
@fclose($file);

// INTESTAZIONI DELLA MAIL
$mail_headers .= "MIME-version: 1.0\n";
$mail_headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"";
$mail_headers .= "X-attachments: $file_name\n";

// CORPO DEL MESSAGGIO
$messaggio = "--$boundary\n";
$messaggio .= "Content-Type: text/plain; charset=us-ascii\n";
$messaggio .= "Content-Transfer-Encoding: 7bit\n\n";
$messaggio .= "testo messaggio";

$messaggio .= "--$boundary\n";
$messaggio .= "Content-type: $file_type; name=\"$file_name\"\n";
$messaggio .= "Content-Transfer-Encoding: base64\n";
$messaggio .= "$encoded_attach\n";
$messaggio .= "--$boundary--\n";

$to = 'dest@destinatario.com';
$posta = 'no-reply@sito.com';

ini_set('sendmail_from', $posta); // Invia email da @miodominio.com
if(@mail($to, $subject, $messaggio, $mail_headers)) {
echo "
E' stata appena inviata una copia del file a $to";
}
else
{
echo "ERRORE..";
}
?>