Vedhæft fil i mail - virker ikke til webmail
Jeg bruger nedenstående script til afsendelse af mail med vedhæftede filer.Når jeg læser emailen i en webmailclient som confixx, hotmail mm, modtager jeg en mail uden vedhæftet fil indeholdende som denne:
--45169b373ca30
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit
test
--45169b373ca30
Content-type: application/unknown; name=test.txt
Content-disposition: attachment; filename=test.txt
Content-transfer-encoding: base64
SSBmZWVsIGl0IGluIG15IGZpbmdlcnMgLSBFcmljIENsYXB0b24NClRpbWUgYWZ0ZXIgdGltZSAt
IEN5bmRpIExhdXBlciBMeXJpY3M=
-------------------------
Script til afsendelse af mail:
//Attachment
$boundary = uniqid("");
$mimeType = "application/unknown";
$filepath = $_FILES['filen']['tmp_name'];
$fil_var = fread(fopen($filepath, "r"), filesize($filepath));
$fil_var = base64_encode($fil_var);
$fil_var = chunk_split($fil_var);
$body = "\n--$boundary\n";
$body .= "Content-type: text/plain; charset=iso-8859-1\n";
$body .= "Content-transfer-encoding: 8bit\n\n";
$body .= $besked."\n\n";
$body .= "--$boundary\n";
$body .= "Content-type: $mimeType; name=$fil\n";
$body .= "Content-disposition: attachment; filename=$fil\n";
$body .= "Content-transfer-encoding: base64\n\n";
$body .= $fil_var."\n\n";
$body .= "--$boundary--";
// Vi definerer from-headeren
$headers = "From: ".$name."<$fra>\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"";
$headers .= "X-Mailer: PHP/";
mail($sendtil, $emne, $body, $headers);
Nogen der ved hvad problemet kan være?
Når jeg henter mail med outlook, virker det fint.
