<?php
  session_start();
  $limit = 3;
  
  if(isset($_SESSION['mailscount'])){
    if($_SESSION['mailscount'] >= $limit){
      header('Location:przekroczony_limit.html');
      exit();
    }
  } else {
    $_SESSION['mailscount'] = 0;
  }
  
  $do = "moj@adres.email";
  if(isset($_POST['temat']) && isset($_POST['tresc'])){
    $temat = $_POST['temat'];
    $tresc = $_POST['tresc'];
    if($temat == "" || $tresc == ""){
      header('Location:zle_dane.html');
    }
    else{
      if(mail($do, $temat, $tresc)){
        $_SESSION['mailscount']++;
        header('Location:dziekuje.html');
      }
      else{
        header('Location:blad_serwera.html');
      }
    }
  }
  else{
    header('Location:zle_dane.html');
  }
?>
