<!DOCTYPE
html PUBLIC "-//
W3C//DTD
HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<
html>
<head>
<title>
Send Attatchments
</title>
</head>
<?php
function SendMail() {
if (isset($_POST['EMail'])) {$EMail = htmlspecialchars($_POST['EMail']);};
if (isset($_POST['Message'])) {$Message = htmlspecialchars($_POST['Message']);};
if (($EMail != '') and ($Message != '')) {
if (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([a-z0-9-]+\.)+([a-z]{2,4})$/i', $EMail)) {
WriteError("Ungültige EMail Addresse");
} else {
$Headers = 'From: ' . $EMail . "\r\n";
$filesuploaded = 0;
foreach($_FILES["files"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["files"]["tmp_name"][$key];
if (is_uploaded_file($tmp_name)) {
$filesuploaded += 1;
};
};
};
if ($filesuploaded > 0) {
$semi_rand = md5(uniqid(time())); // Generate a boundary string
$FileSend = false;
$Headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"$semi_rand\"\n";
$Message = "This is a multi-part message in MIME format.\n" .
"--$semi_rand\n" .
"Content-Type: text/plain; charset=iso-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$Message . "\n\n" ;
foreach($_FILES["files"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["files"]["tmp_name"][$key];
$file_name = $_FILES["files"]["name"][$key];
$file_type = $_FILES["files"]["type"][$key];
if (is_uploaded_file($tmp_name) ) {
$file = fopen($tmp_name,'rb');
$data = fread($file, filesize($tmp_name));
fclose($file);
// Add file attachment to the message
$Message .= "--$semi_rand";
$Message .= "\nContent-Type: $file_type; name=\"$file_name\"";
$Message .= "\nContent-Transfer-Encoding: base64";
$Message .= "\nContent-Disposition: attachment; filename=\"$file_name\"\n";
$Message .= chunk_split(base64_encode($data)); // Base64 encode the file data
$FileSend = true;
};
};
};
if ($FileSend) $Message .= "--$semi_rand--\n\n";
};
if (!mail('grennhorn@everymail.org', 'Mail with Attachments', $Message, $Headers)) {
WriteError("Nachricht konte nicht versendet werden");
};
};
};
};
?>
<body>
<?php SendMail() ?>
<?php function WriteError($Message) {echo $Message; }; ?>
</body>
</
html>