<?
// edit these lines
$your_name="Kredyt studencki - dane z formularza, zadaj pytanie";
$your_email="kredytstudenki@psrp.org.pl";
$your_web_site_name="Kredyt studencki - zadaj pytanie";
?>

<?php 
//If the form is submitted
if(isset($_POST['name'])) {

		//Check to make sure that the name field is not empty
		if(trim($_POST['name']) === '') {
			$hasError = true;
		} else {
			$name = trim($_POST['name']);
		}
		
		//Check to make sure sure that a valid email address is submitted
		if(trim($_POST['email']) === '')  {
			$hasError = true;
		} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
			$hasError = true;
			$errorMessage = "Proszę podać właściwy adres e-mail!";
		} else {
			$email = trim($_POST['email']);
		}

 
		//Check to make sure comments were entered	
		if(trim($_POST['message']) === '') {
			$hasError = true;
		} else {
			if(function_exists('stripslashes')) {
				$comments = stripslashes(trim($_POST['message']));
			} else {
				$comments = trim($_POST['message']);
			}
		}



		//If there is no error, send the email
		if(!isset($hasError)) {

			$emailTo = $your_email;
			$subject = 'Wiadomosc ze strony kredytstudencki.psrp.org.pl z formularz: zadaj pytanie ';
			
			//message body 
			$body  ="Twoje pytanie: $name \n\n";
			$body .="Towj e-mail: $email \n\n";
			$body .="Uwagi: $comments";


			$headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Reply-To: ' . $email;
			
			mail($emailTo, $subject, $body, $headers);

			$emailSent = true;
	}
} 
?>

<?php if(isset($emailSent) == true) { ?>
	<div class="ok_box">
		<h3>Dziękujemy!</h3>
		<p>Twoje pytanie zostało wysłane, postaramy się odpisać jak najszybciej.</p>
	</div>
<?php } ?>

<?php if(isset($hasError) ) { ?>
	<div class="error_box">
		Proszę poprawnie wypełnić pola formularza.
		<br />
		<?php echo $errorMessage;?>
	</div>
<?php } ?>
