ViaThinkSoft CodeLib
This article is in:
CodeLib → Programming aids → PHP
<?php
function sendEmailAttachment($empfaenger, $betreff, $text, $dateiname, $content_type) {
$from = "info@example.com"; // Absender
$hash = md5(date('r', time())); // Zufälliger Hash zur Identifizierung der Multiparts
$header = "From: $from\n"; // E-Mail-Header
$header .= "Content-Type: multipart/mixed; boundary=\"".$hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($dateiname)), 76, "\n");
$data = "
--$hash
$text
--$hash
Content-Type: ".$content_type."; name=\"".basename($dateiname)."\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"".basename($dateiname)."\"
".$attachment."--$hash--";
mail($empfaenger, $betreff, $data, $header);
}
// Beispiel
sendEmailAttachment("foo@example.com", "Test", "Hier\nist\ndein\nAttachment", "pics/viathinksoft.jpg", "image/jpeg");
?>
Victor-Phillip Negoescu
ViaThinkSoft Gründer
ViaThinkSoft Gründer