<?php
define ('MAILTO', "mail@example.org"); // Empfänger hier eintragen
define ('MAILFROM', "Kontaktformular"); // ggfls. Absender hier eintragen
define ('CHARSET', "ISO-8859-15"); // Zeichenkodierung ggfls. anpassen
$Pflichtfelder = array('Nachricht', 'Mail'); // ggfls. weitere Pflichtfelder angeben
$AddHeader = 'Content-Type: text/plain; charset='.CHARSET;
if(MAILFROM) $AddHeader .= chr(13).chr(10).'From: '.MAILFROM;
if($Formular_abgeschickt = !empty($_POST)) {
$Formular_leer = true; set_magic_quotes_runtime(0);
$_POST = array_map('Formular_Daten', $_POST);
}
function Formular_Daten($val) {
global $Formular_leer;
if(is_array($val)) return array_map('Formular_Daten', $val);
if(get_magic_quotes_gpc()) $val = stripslashes($val);
if($val = trim($val)) $Formular_leer = false;
return $val;
}
function Formular_Pflichtfelder() {
global $Pflichtfelder;
$Fehler = '';
foreach ($Pflichtfelder as $Feld) {
$key = str_replace(' ','_',$Feld);
if(!(isset($_POST[$key]) && trim($_POST[$key]))) {
if($Fehler) $Fehler .= '<br />';
$Fehler .= 'Pflichtfeld "' . $Feld . '" nicht ausgefüllt.';
}
}
return $Fehler;
}
function Formular_neu($log='.htPOSTdata.txt') {
if(file_exists($log) && is_readable($log)
&& file_get_contents($log) == print_r($_POST,true))
return false;
if($handle=@fopen($log, 'w')) {
fwrite($handle, print_r($_POST,true)); fclose($handle);
}
return true;
}
function Formular_Check() {
global $Formular_leer;
if($Formular_leer) $Fehler = 'Keine Daten eingetragen.';
elseif(!$Fehler = Formular_Pflichtfelder()) {
if(!Formular_neu()) $Fehler = 'Nachricht war bereits verschickt.';
}
return $Fehler;
}
function Formular_Eingabe($Feldname, $def='') {
if(!empty($_POST[$Feldname])) echo htmlspecialchars($_POST[$Feldname]);
else echo $def;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<title>Kontaktformular</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>" />
</head>
<body>
<h1>Kontakt</h1>
<?php
if($Formular_abgeschickt) {
if($Formular_Fehler = Formular_Check())
echo '<p class="Meldung" id="Fehler">',$Formular_Fehler,'</p>';
elseif(@mail(MAILTO, "Nachricht", print_r($_POST,true), $AddHeader))
echo '<p class="Meldung" id="OK">Nachricht verschickt.</p>';
else echo '<p class="Meldung" id="Fehler">Server-Fehler !</p>';
}
?>
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"
enctype="multipart/form-data" accept-charset="<?php echo CHARSET; ?>">
<fieldset><legend>Kontaktformular</legend>
<p>
<label for="Name">Name:</label>
<input name="Name" id="Name" size="66"
value="<?php Formular_Eingabe('Name'); ?>" />
</p>
<p>
<label for="Mail">Mail:</label>
<input name="Mail" id="Mail" size="66"
value="<?php Formular_Eingabe('Mail'); ?>" />
</p>
<p>
</p>
<p>
<label for="Nachricht">Nachricht:</label>
<textarea name="Nachricht" id="Nachricht" rows="5" cols="50"><?php
Formular_Eingabe('Nachricht'); ?></textarea>
</p>
<p><input type="submit" value="abschicken" /></p>
</fieldset>
</form>
</body>
</html>