Witam. Mam problem z następującym kodem: <?php
function mailing() {
echo "<div id='mailing'>"; $imie = $_POST['imie'];
$email = $_POST['mail'];
$telefon = $_POST['telefon'];
$temat = $_POST['temat'];
$wiadomosc = $_POST['wiadomosc'];
$captcha = $_POST['captcha'];
$message = "<p>Imię i nazwisko: ".$imie."</p> <br>".
"<p>Adres e-mail: ".$email."</p>".
"<p>Temat wiadomości: ".$temat."</p>".
"<p>Treść wiadomości: ".$wiadomosc."</p>";
$headers = "From: $email \n";
$headers .= "MINE-Version: 1.0\n";
$headers .= "Contact-Type: text/html; charset=UTF-8\n";
mail('xxx@gmail.com',$temat, $message, $headers);
$widok = "<div id='podziekowanie'>Wiadomość została wysłana!<br> Dziękujemy. Postaramy się odpowiedzieć najszybciej, jak to tylko możliwe.
<br><br> Za 5 sekund nastąpi przekierowanie na stronę główną. Prosimy czekać.
</div>" ;
return $widok;
};
function form($pola=false) {
return $form = '<div id="formularz">
<form method="post" action="kontakt.php">
<div>
<label for = "imie">Imię i nazwisko * </label>
<input type="text" value = "'.$pola['imie'].'" name="imie" required placeholder="Wpisz imię i nazwisko">
</div>
<br />
<div>
<label for = "mail">Adres e-mail *</label>
<input type="text" value = "'.$pola['mail'].'" name="mail" required placeholder="Twój Adres E-Mail"> <br>
</div>
<br />
<div>
<label for = "telefon">Telefon *</label>
<input type="text" value = "'.$pola['telefon'].'" name="telefon" required placeholder="Podaj swój numer telefonu"> <br>
</div>
<br />
<div>
<label for = "temat">Temat *</label>
<input type="text" value = "'.$pola['temat'].'" name="temat" required placeholder="Nazwa Tematu"><br>
</div>
<br />
<div>
<label for = "wiadomosc">Zapytanie *</label>
<textarea name="wiadomosc" required placeholder="Wiadomość...">'.$pola['wiadomosc'].' </textarea> <br>
</div>
<br /><br />
<div id="captcha">
<label for = "wiadomosc">Captcha *</label>
<img src="image.php"> <br>
<input type="text" value = "'.$pola['captcha'].'" name="captcha" required placeholder="Przepisz kod z obrazka..."><br>
</div>
<br />
<div>
<br>
<input type="reset" value="Wyczyść">
<input type="submit" value="Wyślij">
</div>
</form>
</div>';
}
if ($_POST){
$image = $_POST['image'];
if(empty($_POST['imie'])) { echo "<br><h2><center>Podaj imię i nazwisko!</center></h2><hr>"; }
else if(empty($_POST['mail'])) { echo "<br><h2><center>Podaj adres e-mail!</center></h2><hr>"; }
else if(empty($_POST['temat'])) { echo "<br><h2><center>Podaj temat zapytania!</center></h2><hr>"; }
else if(empty($_POST['wiadomosc'])) { echo "<br><h2><center>Podaj treść zapytania!</center></h2><hr>"; }
echo "<br><h2><center>Podany numer telefonu jest nieprawidłowy!</center></h2><hr>"; }
else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9]+)*@[a-z0-9]+(\.[a-z0-9]+)*(\.[a-z]{2,4})$", $_POST['mail'])) { echo "<br><h2><center>Wprowadzony adres e-mail jest niepoprawny!</center></h2><hr>"; }
else if(empty($_POST['captcha'])) { echo "<br><h2><center>Proszę podać kod!</center></h2><hr>"; }
else if($_POST['captcha'] != $image) {
echo "<br><h2><center>Proszę podać poprawny kod!</center></h2><hr>"; }
else if($image == $_SESSION['string']) {
}
?>
Problem polega na tym, że kod wysyła formularz zawsze pomimo złego kodu captcha. Próbowałem na kilka sposobów i nic mi nie wychodzi. Podsyłam jeszcze plik image.php<?php
$img = imagecreatetruecolor(150,40);
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$grey = imagecolorallocate($img,150,150,150);
$red = imagecolorallocate($img, 255, 0, 0);
$pink = imagecolorallocate($img, 200, 0, 150);
function randomString($length){
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
$str = "";
$i = 0;
while($i <= $length){
$tmp = substr($chars, $num, 1
); $str = $str . $tmp;
$i++;
}
return $str;
}
for($i=1;$i<=rand(1
,5
);$i++){ $color = (rand(1
,2
) == 1
) ?
$pink : $red; }
imagefill($img, 0, 0, $white);
$string = randomString
(rand(7
,10
)); $_SESSION['string'] = $string;
imagettftext($img, 18, 0, 10, 20, $black, "Arial.ttf", $string);
header("Content-type: image/png"); imagepng($img);
imagedestroy($img);
?>