<?php
# Adresse, an die die Formulardaten gesendet werden sollen:
$mailto = "gewinn@mydomain.de";
# Maximale Größe des Attachments in Bytes:
$max_attach_size = 500000;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html>
<head>
<title>Gewinnspiel-Mailer</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000; background: #ffff3; margin: 20px; padding: 0px; border: 0px; }
.caution { color: red; font-weight: bold; }
-->
</style>
</head>
<body>
<?php
if (isset($_POST["form_submitted"]))
{
// übergebene Variablen ermitteln:
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$text = $_POST['text'];
// Überprüfungen der Daten:
unset($errors);
if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "die E-Mail-Adresse sieht nicht richtig aus";
if ($text == "") $errors[] = "es wurde kein Text eingegeben";
if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Attachment zu groß (".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - Maximalgröße: ".number_format($max_attach_size/1000,0,",","")." KB";
if (empty($errors))
{
$text = stripslashes($text);
$subject = stripslashes($subject);
if ($name != "") $mail_name=$name; else $mail_name="unbekannt";
if ($subject != "") $mail_subject = $subject; else $mail_subject = "kein Betreff";
if ($email != "") $mail_email = $email; else $mail_email = "email@unknown.xyz";
$ip = $_SERVER["REMOTE_ADDR"];
// Wenn Attachment, dann MIME-Mail erstellen:
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "")
{
// Datei einlesen und codieren:
$datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),filesize($_FILES['probe']['tmp_name']));
$datei_content = chunk_split(base64_encode($datei_content),76,"\n") ;
// Boundary festlegen:
$boundary = md5(uniqid(rand()));
// Mail-Header:
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: ".$ip."\n";
$mail_header .= "MIME-Version: 1.0\n";
$mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$mail_header .= "This is a multi-part message in MIME format.\n";
// Mail-Text:
$mail_header .= "--".$boundary;
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\nContent-Transfer-Encoding: 8bit";
$mail_header .= "\n\n".$text;
// Attachment:
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: ".$_FILES['probe']['type']."; name=\"".$_FILES['probe']['name']."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\"".$_FILES['probe']['name']."\"";
$mail_header .= "\n\n".$datei_content;
// Ende:
$mail_header .= "\n--".$boundary."--";
// Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
if (@mail($mailto,$mail_subject,"",$mail_header,"-f Mail@mydomain.de")) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
}
// kein Attachment, normale E-Mail:
else
{
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: $ip\n";
$mail_header .= "Content-Type: text/plain";
if (@mail($mailto,$mail_subject,$text,$mail_header,"-f Mail@mydomain.de")) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
}
// Kopie an Absender:
if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
{
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text;
$header= "From: ".$mailto."\n";
$header .= "X-Sender-IP: ".$ip."\n";
$header .= "Content-Type: text/plain";
@mail($email, $mail_subject, $copy_mail_text, $header,"-f Mail@mydomain.de");
}
}
}
if (empty($sent))
{
if(isset($errors))
{
?><p class="caution">Fehler:</p><ul><?php foreach($errors as $f) { ?>[*]<?php echo $f; ?><?php } ?>[/list]
<?php
}
?><form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"><div>
Name:
<input type="text" name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="35" /></p>
E-Mail:
<input type="text" name="email" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="35" /></p>
Betreff:
<input type="text" name="subject" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="35" /></p>
Nachricht:
<textarea name="text" cols="55" rows="12"><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?></textarea></p>
Attachment:
<input type="file" name="probe" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="20"/></p>
<input type="submit" name="form_submitted" value="OK - Absenden" /> <input type="checkbox" name="copy" value="true" /> Kopie an Absender</p>
</div></form><?php
}
else
{
if (empty($email)) { ?>
Danke!
Nachricht erfolgreich versendet. Es wurde aber keine E-Mail-Adresse angegeben.</p><?php }
else { ?>
Danke!
Nachricht erfolgreich versendet.</p><?php }
}
?>
</body>
</html>
--------------------------------------
Die Roten stellen natürlich angepasst, da der Server gelegentlich probleme mit dem Versand im PHPKit hatte und nach dieser Aktion einwandfrei lief. Wenn ich dieses Script ausführe bringt es mir keine Fehlermeldung oder sonstiges. Nur leider kommt auch keine Mail an.
Mfg
Kenny
# Adresse, an die die Formulardaten gesendet werden sollen:
$mailto = "gewinn@mydomain.de";
# Maximale Größe des Attachments in Bytes:
$max_attach_size = 500000;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html>
<head>
<title>Gewinnspiel-Mailer</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000; background: #ffff3; margin: 20px; padding: 0px; border: 0px; }
.caution { color: red; font-weight: bold; }
-->
</style>
</head>
<body>
<?php
if (isset($_POST["form_submitted"]))
{
// übergebene Variablen ermitteln:
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$text = $_POST['text'];
// Überprüfungen der Daten:
unset($errors);
if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "die E-Mail-Adresse sieht nicht richtig aus";
if ($text == "") $errors[] = "es wurde kein Text eingegeben";
if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Attachment zu groß (".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - Maximalgröße: ".number_format($max_attach_size/1000,0,",","")." KB";
if (empty($errors))
{
$text = stripslashes($text);
$subject = stripslashes($subject);
if ($name != "") $mail_name=$name; else $mail_name="unbekannt";
if ($subject != "") $mail_subject = $subject; else $mail_subject = "kein Betreff";
if ($email != "") $mail_email = $email; else $mail_email = "email@unknown.xyz";
$ip = $_SERVER["REMOTE_ADDR"];
// Wenn Attachment, dann MIME-Mail erstellen:
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "")
{
// Datei einlesen und codieren:
$datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),filesize($_FILES['probe']['tmp_name']));
$datei_content = chunk_split(base64_encode($datei_content),76,"\n") ;
// Boundary festlegen:
$boundary = md5(uniqid(rand()));
// Mail-Header:
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: ".$ip."\n";
$mail_header .= "MIME-Version: 1.0\n";
$mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$mail_header .= "This is a multi-part message in MIME format.\n";
// Mail-Text:
$mail_header .= "--".$boundary;
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\nContent-Transfer-Encoding: 8bit";
$mail_header .= "\n\n".$text;
// Attachment:
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: ".$_FILES['probe']['type']."; name=\"".$_FILES['probe']['name']."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\"".$_FILES['probe']['name']."\"";
$mail_header .= "\n\n".$datei_content;
// Ende:
$mail_header .= "\n--".$boundary."--";
// Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
if (@mail($mailto,$mail_subject,"",$mail_header,"-f Mail@mydomain.de")) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
}
// kein Attachment, normale E-Mail:
else
{
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: $ip\n";
$mail_header .= "Content-Type: text/plain";
if (@mail($mailto,$mail_subject,$text,$mail_header,"-f Mail@mydomain.de")) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
}
// Kopie an Absender:
if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
{
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text;
$header= "From: ".$mailto."\n";
$header .= "X-Sender-IP: ".$ip."\n";
$header .= "Content-Type: text/plain";
@mail($email, $mail_subject, $copy_mail_text, $header,"-f Mail@mydomain.de");
}
}
}
if (empty($sent))
{
if(isset($errors))
{
?><p class="caution">Fehler:</p><ul><?php foreach($errors as $f) { ?>[*]<?php echo $f; ?><?php } ?>[/list]
<?php
}
?><form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"><div>
Name:
<input type="text" name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="35" /></p>
E-Mail:
<input type="text" name="email" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="35" /></p>
Betreff:
<input type="text" name="subject" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="35" /></p>
Nachricht:
<textarea name="text" cols="55" rows="12"><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?></textarea></p>
Attachment:
<input type="file" name="probe" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="20"/></p>
<input type="submit" name="form_submitted" value="OK - Absenden" /> <input type="checkbox" name="copy" value="true" /> Kopie an Absender</p>
</div></form><?php
}
else
{
if (empty($email)) { ?>
Danke!
Nachricht erfolgreich versendet. Es wurde aber keine E-Mail-Adresse angegeben.</p><?php }
else { ?>
Danke!
Nachricht erfolgreich versendet.</p><?php }
}
?>
</body>
</html>
--------------------------------------
Die Roten stellen natürlich angepasst, da der Server gelegentlich probleme mit dem Versand im PHPKit hatte und nach dieser Aktion einwandfrei lief. Wenn ich dieses Script ausführe bringt es mir keine Fehlermeldung oder sonstiges. Nur leider kommt auch keine Mail an.
Mfg
Kenny
Kommentar