Mit diesem PHP-Script kann eine E-Mail mit Anhang (z.B: Grafik)
versendet werden.
Quelltext:
<?php
$empfaenger = "empfaenger@mailadresse.xy"; // Empfänger E-Mail Adresse
$betreff = "E-Mail mit Anhang"; // Betreff
$dateiname = "bild.gif"; // Dateiname
$dateiname_mail = "anhang.gif";
$id = md5(uniqid(time()));
$dateiinhalt = fread(fopen($dateiname, "r"), filesize($dateiname));
// Absender Name und E-Mail Adresse
$kopf = "From: Manfred Mustermann <meine@mailadresse.xy>\n";
$kopf .= "MIME-Version: 1.0\n";
$kopf .= "Content-Type: multipart/mixed; boundary=$id\n\n";
$kopf .= "This is a multi-part message in MIME format\n";
$kopf .= "--$id\n";
$kopf .= "Content-Type: text/plain\n";
$kopf .= "Content-Transfer-Encoding: 8bit\n\n";
$kopf .= "E-Mail mit Anhang"; // Inhalt der E-Mail (Body)
$kopf .= "\n--$id";
// Content-Type: image/gif, image/jpeg, image/png » MIME-Typen - selfHtml.org
$kopf .= "\nContent-Type: image/gif; name=$dateiname_mail\n";
$kopf .= "Content-Transfer-Encoding: base64\n";
$kopf .= "Content-Disposition: attachment; filename=$dateiname_mail\n\n";
$kopf .= chunk_split(base64_encode($dateiinhalt));
$kopf .= "\n--$id--";
mail($empfaenger, $betreff, "", $kopf); // E-Mail versenden
?>