<?PHP
	if(isset($errorMsg) && $errorMsg) 
	{
		echo "<p style=\"color: red;\">*",htmlspecialchars($errorMsg),"</p>\n\n";
	}

	
	if(isset($_POST['email']) && $_POST['email'])
	{
		$headers   = array();
		$headers[] = "MIME-Version: 1.0";
		$headers[] = "Content-type: text/plain; charset=UTF-8";
		$headers[] = "From: Website <info@it-consulting-wessling.de>";
		$headers[] = "X-Mailer: PHP/".phpversion();
		mail('info@it-consulting-wessling.de', 'Website Spam', 'Spam Mail',implode("\r\n",$headers));
	}
	
	function after ($this, $inthat)
	{
		if (!is_bool(strpos($inthat, $this)))
		return substr($inthat, strpos($inthat,$this)+strlen($this));
	}

	function ping($email)
	{			
		$host = after ('@', $email);
		if ( checkdnsrr("$host", "ANY") )
		{
			return false;
		}
		else 
		{
			return true ;
		}
	}
	

	if($_POST && isset($_POST['name'], $_POST['company'], $_POST['mail'], $_POST['phone'], $_POST['nachricht'])) 
	{
		$name = $_POST['name'];
		$company = $_POST['company'];
		$mail = $_POST['mail'];
		$phone = $_POST['phone'];
		$nachricht = $_POST['nachricht'];

		$message = "Name: $name \nFirma: $company \nMail: $mail \nTelefon: $phone \nNachricht: $nachricht";
		
		if(!$name) 
		{
			$errorMsg = "Bitte einen Namen angeben.";
		}
		elseif(ping($mail) === true)
		{
			$errorMsg = "Bitte eine gültige E-Mail Adresse eingeben.";
		}
		else
		{			
			$headers   = array();
			$headers[] = "MIME-Version: 1.0";
			$headers[] = "Content-type: text/plain; charset=UTF-8";
			$headers[] = "From: Website <info@it-consulting-wessling.de>";
			$headers[] = "X-Mailer: PHP/".phpversion();
		
			$empfaenger = "info@it-consulting-wessling.de";
			$betreff = "Anfrage vom Websiteformular";
			
			mail($empfaenger, $betreff, $message,implode("\r\n",$headers));
			
			header("Location: /thanks.php");
			exit;
		}
	}

	include "include/header.php" 
?>
		<div class="box effect" id="content"> 
			<div id="top">
				<h1>Kontakt</h1>
			</div>
			<div class="line"></div>
			<div id="center"><p>Haben Sie Fragen, Wünsche oder Anregungen? Bitte nehmen Sie Kontakt mit uns auf, wir helfen Ihnen gerne weiter!</p></div>
			<div id="bottom">
				<p><b>Kontaktformular</b></p><br>
				<form name="kontaktformular" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" accept-charset="UTF-8">
					<?PHP
						if(isset($errorMsg) && $errorMsg) 
						{
							echo "<p style=\"color: red;\">*",htmlspecialchars($errorMsg),"</p>\n\n";
						}
					?>
					<div>
					  <label for="name"><span>Name:</span> * </label>
					  <input type="text" id="name" name="name" onkeyup="chkName()" onchange="chkName()" required="required" value="<?PHP if(isset($_POST['name'])) echo htmlspecialchars($_POST['name']); ?>"/>
					  <img id="name_ok" src="/images/ok.jpg" height="30" width="25" />
					  <img id="name_nok" src="/images/nok.jpg" height="30" width="25" />
					</div>
					<div>
					  <label for="company"><span>Firma:</span></label>
					  <input type="text" id="company" name="company" value="<?PHP if(isset($_POST['company'])) echo htmlspecialchars($_POST['company']); ?>" />
					</div>
					<div class="mail">
						<label>E-mail</label>
						<input type="text" name="email" />
					</div>
					<div>
					  <label for="mail"><span>E-Mail Adresse:</span> * </label>
					  <input type="text" id="mail" name="mail" onkeyup="chkMail()" onchange="chkMail()" title="name@domain.de" required="required" value="<?PHP if(isset($_POST['mail'])) echo htmlspecialchars($_POST['mail']); ?>"/>
					  <img id="mail_ok" src="/images/ok.jpg" height="30" width="25" />
					  <img id="mail_nok" src="/images/nok.jpg" height="30" width="25" />
					</div>
					<div>
					  <label for="phone"><span>Telefon:</span></label>
					  <input type="text" id="phone" name="phone" value="<?PHP if(isset($_POST['phone'])) echo htmlspecialchars($_POST['phone']); ?>" />
					</div>
					<div>
					  <label for="nachricht">Ihre Nachricht:</span> * </label>
					  <textarea id="nachricht" name="nachricht" onkeyup="chkText()" onchange="chkText()" required="required" cols="20" rows="5"><?PHP if(isset($_POST['nachricht'])) echo htmlspecialchars($_POST['nachricht']); ?></textarea>
					  <img id="nachricht_ok" src="/images/ok.jpg" height="30" width="25" />
					  <img id="nachricht_nok" src="/images/nok.jpg" height="30" width="25" />
					</div>
					<div>
						<p class="node"> <strong class="node">Hinweis</strong>: Felder, die mit <em>*</em> bezeichnet sind, sind Pflichtfelder. </p>
					</div>
					<div>
					  <input type="submit" value="Abschicken" />
					</div>
				</form>
			</div>					
		</div>

		
<?php include "include/footer.php" ?>	



