Nel codice che utilizzo io definisco header e body nella maniera seguente e tutto funziona correttamente:
[PHP]
$destinatario = "xxx";
$subject = "yyy";
$mittente = ""zzz" [email protected]";
$message = "testo del messaggio";
$attach = $_FILES['attach']['tmp_name'];
$filetype = $_FILES['attach']['type'];
$nomeAllegato = $_FILES['attach']['name'];
if (is_uploaded_file($attach)) {
$filez = fopen($attach, "r");
$contents = fread($filez, filesize($attach));
$encoded_attach = chunk_split(base64_encode($contents));
fclose($filez);
// CREO L'INTESTAZIONE
$header = "From: $mittente\n";
$header .= "X-Mailer: Sismail Web Email Interface\n";
$header .= "MIME-version: 1.0\n";
$header .= "Content-type: multipart/mixed;\n";
$header .= " boundary="Message-Boundary"\n";
$header .= "Content-transfer-encoding: 7BIT\n";
$header .= "X-attachments: $nomeAllegato";
// CREO IL MESSAGGIO
$body = "--Message-Boundary\n";
$body .= "Content-type: text/plain; charset=iso-8859-1\n";
$body .= "Content-transfer-encoding: 7BIT\n";
$body .= "Content-description: Mail message body\n\n";
$body .= $message . "\n\n";
$body .= "\n\n--Message-Boundary\n";
$body .= "Content-type: $filetype; name="$nomeAllegato"\n";
$body .= "Content-Transfer-Encoding: BASE64\n";
$body .= "Content-disposition: attachment; filename="$nomeAllegato"\n\n";
$body .= "$encoded_attach\n";
$body .= "--Message-Boundary--\n";
@mail($destinatario, $subject, $body, $header);
}
[/PHP]