<?php
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Kontaktformular.org
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


// Einstellungen

// Ihre E-Mailadresse
$ihre_emailadresse = 'kontakt@es-ulm.de';

// Absender || Muster(From: NAME <EMAIL>) // Beispiel: 'From: Max Mustermann <max@musterdomain.tld>'
$email_absender = 'From: Kontaktformular <kontakt@es-ulm.de>';

// Betreff
$email_betreffzeile = 'Nachricht vom Kontaktformular';



// Hinweismeldungen

#Nicht alle Felder ausgefüllt
$errormessage[0] = 'Falsche Eingabe bei:';
#Kein Name eingegeben
$errormessage[1] = ' Name';
#Ungültige E-Mailadresse eingegeben
$errormessage[2] = ' E-Mail';
#Kein Betreff eingegeben
$errormessage[3] = ' Betreff';
#Keine Nachricht eingegeben
$errormessage[4] = ' Nachricht';
#Ungültiger Sicherheitscode
$errormessage[5] = ' Sicherheitscode';
#Ungültiger Zeichen (Spamverdacht)
$errormessage[6] = ' Ungültige Zeichen entdeckt';

#Alle Felder sind OK
$okay = 'Vielen Dank für Ihre Nachricht!';





// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    #######################################
    session_start();
    #######################################


	  if(isset($_POST['submit'])) {
    #######################################

	  $name =       check($_POST['name']);
	  $email =      check($_POST['email']);
	  $telefon =    check($_POST['telefon']);
	  $nachricht =  check($_POST['nachricht']);
	  $betreff =   check($_POST['betreff']);

    #######################################

		$ip = $_SERVER['REMOTE_ADDR'];
		$host = gethostbyaddr($ip);

    #######################################

		$zeit = time();
		$datum = date ("d.m.Y", $zeit);
		$uhrzeit = date ("H:i:s", $zeit);

    #######################################

		$message = '<span style="color:red">' . $errormessage[0];
		
    if($name==''){$message .= $errormessage[1]; $fehler = 1;}
		
    if(!ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,6})$", $email)) {
			$message .= $errormessage[2]; $fehler = 1;}
		
    if($betreff==''){$message .= $errormessage[3]; $fehler = 1;}
		
    if($nachricht==''){$message .= $errormessage[4];	$fehler = 1;}
		
    if($_POST['code']=="" || strtolower($_POST['code'])!=$_SESSION['captcha_code']){
			$message .= $errormessage[5]; $fehler = 1;}
    
    if(ehi_check()!=0){$message .= $errormessage[6];  $fehler = 1;}

		$message .= '</span>';

		#######################################

    #######################################
        
        if(!isset($fehler)){
			
        $email_nachricht  = "-- Kontakformularanfrage --\n\nBetreff: $betreff";
		$email_nachricht .= "\nName: $name\n";
		$email_nachricht .= "\nE-Mail-Adresse: $email\n";
		$email_nachricht .= "\nTelefon: $telefon\n";
        $email_nachricht .= "\nNachricht:\n$nachricht\n\nIP: $ip\nHost: $host\n";
        $email_nachricht .= "gesendet am $datum um $uhrzeit.";
			 
        // Mail senden
        @mail($ihre_emailadresse, $email_betreffzeile, $email_nachricht, $email_absender, $email_telefon);
			
        //Variablen resetten
        $name       = '';
			  $betreff    = '';
			  $email      = '';
			  $nachricht  = '';
		      $telefon    = '';
			
        $meldung=$okay;
  
		    } else {
		    $meldung=$message;
		    }
    #######################################
    #######################################
	} //endissetsubmit
  else{$meldung='';}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Kontaktformular</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-script-type" content="text/javascript" />

<style type="text/css">
body,td,th{
	font-family:Arial, Helvetica, sans-serif;
	font-size:9pt;
	color:#3d3d3d;
}
body{
	background-color: #FFFFFF;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-image: url();
	background-repeat: no-repeat;
}
a:link, a:visited, a:active{color:#0066FF;text-decoration:none;}
a:hover{
	text-decoration: underline;
	color: #FFFFFF;
}
.Stil1 {color: #FFFFFF}
a:link {
	color: #FFFFFF;
}
a:visited {
	color: #FFFFFF;
}
a:active {
	color: #FFFFFF;
}
.Stil2 {font-family: Arial}
</style>

<script type="text/javascript">
function reload_captcha(){ 
var nd = new Date();
var src="captcha.php?"+nd;
document.getElementById("captcha").src= src;
}
</script>

</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="kontaktformular" class="Stil2">

<table style="width:562px" background="" cellspacing="0" cellpadding="0">
<tr><td height="18" colspan="2"><?php echo $meldung; ?></td>
</tr>
<tr>
	<td width="152" height="25" style="width:150px">Name:</td>
	<td width="408"><input name="name" type="text" value="<?php echo $name;	?>" size="40" maxlength="100" /></td>
</tr>
<tr>
	<td height="25" style="width:150px">E-Mail Adresse:<br />	</td>
	<td><input name="email" type="text" id="email" value="<?php echo $email; ?>" size="40" maxlength="100" /></td>
</tr>
<tr>
	<td height="25" style="width:150px">Telefon:</td>
	<td><input name="telefon" type="text"  value="<?php echo $telefon; ?>" size="40" maxlength="50" /></td>
</tr>
<tr>
	<td height="25" style="width:150px">Betreff:</td>
	<td><input name="betreff" type="text"  value="<?php echo $betreff; ?>" size="40" maxlength="50" /></td>
</tr>
<tr>
	<td style="width:150px">Nachricht:<br />
	  <span class="Stil1" style="font-size:10px">&copy; Script Powered by <a target="_blank" href="http://www.kontaktformular.org" title="Kontaktformular">Kontaktformular</a></span></td>
	<td valign="top"><textarea name="nachricht" cols="30" rows="2" wrap="VIRTUAL" id="nachricht"><?=$nachricht;
	?></textarea></td>
</tr>
<tr>
<td style="width:150px">Sicherheitscode:</td>
	<td>
	<table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0" height="42">
		<tr>
			<td width="106"><img id="captcha" src="http://www.es-ulm.de/kontaktformular/captcha.php" alt="captcha" border="1"  /></td>
		</tr>
	</table>	</td>
</tr>
</table>
<table border="0" width="562" id="table2" cellspacing="0" cellpadding="0">
	<tr>
		<td width="156">Code wiederholen:</td>
	  <td width="82">	      <input name="code" type="text"  size="12" maxlength="50" /></td>
	  <td width="324"> 
		<table border="0" width="100%" id="table3" cellspacing="0" cellpadding="0">
			<tr>
				<td width="14">&nbsp;</td>
			  <td>&nbsp;</td>
			</tr>
		</table>	  </td>
	</tr>
</table>
<table width="510" border="0">
  <tr>
    <td width="144">&nbsp;</td>
    <td width="356"><input type="submit" value="Nachricht abschicken" name="submit" /></td>
  </tr>
</table>
</form>
</body>
</html>
<?php 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 


function check($var){
$varsafe=trim(strip_tags($var));
return $varsafe;
}


function ehi_check(){
$achtung=0;
foreach($_POST as $val){
$pos = strpos(strtolower($val), 'content-type:'); if($pos !== false){$achtung++;}
$pos = strpos(strtolower($val), 'content-type');  if($pos !== false){$achtung++;}
$pos = strpos(strtolower($val), 'bcc:');          if($pos !== false){$achtung++;}
$pos = strpos(strtolower($val), 'bcc');           if($pos !== false){$achtung++;}
} //endforeach
return $achtung;  // wenn Null dann Alles Okay
} 


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
?>