<?php
$formtresc = "
<style type='text/css'>
input{
display: block;
}
</style>
<div form-wrapper style='width: 400px; height: 500px; margin: 0 auto;'>
<center>
<form action='mail.php' method='get'>
<div class='error' id='imie'></div>
Your name: <input type='text' name='imie' />
<div class='error' id='email'></div>
Your e-mail: <input type='text' name='email' />
Select subject of your message: <div class='error' id='temat'></div>
<select name='subject'>
<option>Default</option>
<option>Bug report</option>
<option>Grats</option>
</select></br>
Your message: <textarea name='message' cols='50' rows='10'></textarea></br></br>
<input type='submit' name='send' value='Dalej'/>
</form>
</center>
</div>
";
$formtrescE1 = "<form action='mail.php' method='get'>
<div class='error' id='imie'>Podaj imie!</div>
<input type='text' name='imie' /></br>
<div class='error' id='email'></div>
<input type='text' name='email' />
<div class='error' id='temat'></div>
<select name='subject'>
<option>Default</option>
<option>Bug report</option>
<option>Grats</option>
</select>
<textarea name='message' cols='50' rows='10'>Tresc wiadomosci</textarea>
<input type='submit' value='Dalej'/>
</form>";
$formtrescE2 = "<form action='mail.php' method='get'>
<div class='error' id='imie'></div>
<input type='text' name='imie' /></br>
<div class='error' id='email'>Podaj email</div>
<input type='text' name='email' />
<div class='error' id='temat'></div>
<select name='subject'>
<option>Default</option>
<option>Bug report</option>
<option>Grats</option>
</select>
<textarea name='message' cols='50' rows='10'>Tresc wiadomosci</textarea>
<input type='submit' value='Dalej'/>
</form>";
$formtrescE3 = "<form action='mail.php' method='get'>
<div class='error' id='imie'></div>
<input type='text' name='imie' /></br>
<div class='error' id='email'></div>
<input type='text' name='email' />
<div class='error' id='temat'>Podaj temat wiadomosci</div>
<select name='subject'>
<option>Default</option>
<option>Bug report</option>
<option>Grats</option>
</select>
<textarea name='message' cols='50' rows='10'>Tresc wiadomosci</textarea>
<input type='submit' value='Dalej'/>
</form>";
$formtrescE4 = "<form action='mail.php' method='get'>
<div class='error' id='imie'></div>
<input type='text' name='imie' /></br>
<div class='error' id='email'></div>
<input type='text' name='email' />
<div class='error' id='temat'></div>
<select name='subject'>
<option>Default</option>
<option>Bug report</option>
<option>Grats</option>
</select>
<div class='error' id='message'>Podaj tresc wiadomosci</div>
<textarea name='message' cols='50' rows='10'></textarea>
<input type='submit' value='Dalej'/>
</form>";
#--------------Temporary Settings--------#
# error id:
# 1 - brak imienia
# 2 - brak emaila
# 3 - nie wybrany temat
# 4 - brak tresci maila
#$_GET['error']['id'] = '4';
#-------------End of temp. settings------#
#--------Configuration File Info---------#
#--------------READ THIS!----------------#
#
# First Line: There you have an e-mail
# address. Messages will be send to
# that e-mail!
#
# Second Line: There you have color
# of border of the inuts
#
#
#
#
#-----End of conf. file info-------------#
#-------------Functions------------------#
function errorExist(){
$error = isset($_GET['error']); #var_dump($a);
#print_r($_GET);
return $error;
}
function errorIdChecker(){ # funkcja zamiast 'echo' ma zwracac id bledu dla innej funkcji
if ($_GET['error']['id'] == 1) {
#echo 'brak imienia';
return 1;
} elseif ($_GET['error']['id'] == 2) {
#echo "brak emaila";
return 2;
} elseif ($_GET['error']['id'] == 3) {
#echo "brak tematu";
return 3;
} elseif ($_GET['error']['id'] == 4) {
#echo "wpisz tresc wiadomosci";
return 4;
}
} #END OF errorIdChecker function
function makePage($errorID, $trescE1, $trescE2, $trescE3, $trescE4){ // wyswietlanie odpoiedniej tresci
switch ($errorID) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
echo "Wystapił niesnany błąd"; echo "<a href='mail.php'>Go Back</a>"; break;
}# Switch end
} #END OF makePage function
function catchError(){
if (empty($_GET['imie'])){ $_GET['error']['id'] = 1;
return;
}
if (empty($_GET['email']) or
!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_GET['email'])) { $_GET['error']['id'] = 2;
return;
}
if ($_GET['subject'] == 'Default') {
$_GET['error']['id'] = 3;
return;
}
if (empty($_GET['message'])) { $_GET['error']['id'] = 4;
return;
}
}
function loadConfigFile(){
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
@ $file = fopen('config.txt', 'r');
if (!$file) {
echo "Blad otwarcia pliku konfiguracyjnego"; } else {
for ($i=0; !feof($file); $i++) {
$config[] = fgetcsv($file, 999, "]"); #print_r($config);
}
}
return $config;
}
#var_dump($errorE);
if(isset($_GET['send'])){ catchError();
$errorE = errorExist(); //sprawdzanie czy przy ladowaniu strony jest jakis error $errorE = false/true
if ($errorE == true) {
$errorId = errorIdChecker();
makePage($errorId, $formtrescE1, $formtrescE2, $formtrescE3, $formtrescE4);
#print_r($a);
} else{
$configf = loadConfigFile();
$message = $_GET['message']."
Author e-mail addres: ".$_GET['email'];
mail($configf[0
][0
], $_GET['subject'], /*$_GET['message']*/$message); //not working on localhost }
} else {
#echo $_SERVER['DOCUMENT_ROOT'];
}
// Imie
// email
// kategoria
// tresc
// dodawanie wyrazow/liczb
?>