<?php

$fileatt = $file;
$fileatt_name = "R_" . $Jahr . "_" . $ID . ".pdf";
$email_from = "RIST <info@ri-st.de>";
$email_subject = "Ihre RIST - Startup! Bestellung";
$email_message = $text;
$email_to = $_POST['Email'];

$fileatt_type = "application/octet-stream"; // File Type

$headers = "From: " . $email_from . "\n";
$headers .= "Reply-To: " . $email_from . "\n";
$headers .= "BCC: <info@ri-st.de>";

$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
	"Content-Type: multipart/mixed;\n" .
	" boundary=\"{$mime_boundary}\"";

$email_message = "This is a multi-part message in MIME format.\n\n" .
	"--{$mime_boundary}\n" .
	"Content-Type:text; charset=\"utf-8\"\n" .
	"Content-Transfer-Encoding: 8bit\n\n" .
	$email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
	"Content-Type: {$fileatt_type};\n" .
	" name=\"{$fileatt_name}\"\n" .
	//"Content-Disposition: attachment;\n" .
	//" filename=\"{$fileatt_name}\"\n" .
	"Content-Transfer-Encoding: base64\n\n" .
	$data . "\n\n" .
	"--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if (!$ok)
{
	die("<h1>Die Nachricht konnte nicht versendet werden. Bitte gehen Sie zurück und versuchen Sie es noch einmal!</h1>");
}