Ho un piccolo problema con l'invio mail con allegato in PHP.
Ho utilizzato il tutorial del sito, ma quando mi arriva l'allegato, risulta di 0 byte, praticamente è vuoto. Il nome del file è quello giusto, ma non si riesce ad aprire in quanto vuoto.
Vi posto il cuore del codice:
Codice PHP:
// ASSEGNIAMO A VARIABILI PIU' LEGGIBILI, LE PROPRIETA' DELL'ALLEGATO
$attach = $_FILES["allegato"]["tmp_name"];
$file_name = $_FILES["allegato"]["name"];
$file_type = $_FILES["allegato"]["type"];
$file_size = $_FILES["allegato"]["size"];
// DELIMITATORE
$boundary = md5(uniqid(microtime()));
if (is_uploaded_file($attach))
{
// APRIAMO L'ALLEGATO PER LEGGERLO E 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";
$mail_headers .= "FROM: Contatti DevSpot <$mail>\r\n";
$mail_headers .= "Return-path: $mail";
// COSTRUIAMO IL CORPO DELLA MAIL
$mail_body = "--$boundary\n";
$mail_body .= "Content-Type: text/plain; charset=us-ascii\n";
$mail_body .= "Content-Transfer-Encoding: 7bit\n\n";
$mail_body .= "$testo\n\n";
$mail_body .= "--$boundary\n";
$mail_body .= "Content-type: $file_type; name=\"$file_name\"\n";
$mail_body .= "Content-Transfer-Encoding: base64\n";
$mail_body .= "$encoded_attach\n";
$mail_body .= "--$boundary--\n";
if (mail($target_mail, $oggetto, $mail_body, $mail_headers))
print ("INVIO CORRETTO");
else print ("ERRORE");
}