Tengo un formulario que quiero combinarlo con un captcha. De momento me conformo con que funcione.
El caso es que no funciona y como soy inexperta en PHP no encuentro el fallo.
Este es el código de correo.php
<?php
session_start();
if ($_POST['action'] == "checkdata") {
if ($_SESSION['tmptxt'] == $_POST['tmptxt']) {
$status = 1;
} else {
$errorCaptcha = "error";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Contacto</title>
<span><span class="Estilo3">Envíanos tu comentario:</span></span>
<form action="enviar.php" method="POST">
<label for="nombre" class="Estilo4">Nombre y apellidos:</label><br />
<input type="text" name="nombre" id="nombre"><br>
<label for="tema" class="Estilo4">E-Mail:</label><br />
<input type="text" name="correo" id="correo"><br>
<label for="tema" class="Estilo4">Tema de su comentario:</label><br />
<input type="text" name="tema" id="tema"><br>
<label for="comentario" class="Estilo4">Escriba su comentario:</label><br />
<textarea name="mensaje" cols="30" rows="6" id="mensaje"></textarea><br>
<?php if($status != 1){ ?>
<form id="form1" action="correo.php" method="post">
<label for="username" class="Estilo4">Introduce el texto mostrado en la imagen</label>
<br><br>
<img src="captcha.php" width="100" height="40"><br><br>
<input tabindex="1" name="tmptxt" id="username" type="text" class="text
<?php if ($errorCaptcha == "error"){ echo "error";} ?>" ><br>
<input name="action" type="hidden" value="checkdata"><br>
<input type="submit" class="boton" value="Validar texto" style="cursor:hand">
</form>
<?php }else
echo "Texto introducido correctamente";
?>
<input name="restablecer" type="reset" />
<input type="submit" value="Enviar" id="submit"><br><br />
</form>
Este es el código de enviar.php
<?php
$name = $_POST['nombre'];
$mail = $_POST['mail'];
$tema = $_POST['tema'];
$msg = $_POST['mensaje'];
$carta = "Nombre: ".$name."<br>Correo: ".$mail."Tema: ".$tema."<br>Mensaje: ".$msg;
$micorreo = "
micorreo@mio.com";
$asunto = "Datos del formulario de contacto";
$headers = "MINE-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: micorreo. <
micorreo@mio.com>\r\n";
$headers .= "Reply-To:
micorreo@mio.com\r\n";
mail($micorreo,$asunto,$carta,$headers);
echo "<meta http-equiv='Refresh' content='1;url=correo.html'>";
?>
Y por último este es el captcha
<?php
session_start();
function randomText($length) {
$pattern = "123456789abcdefghijklmnpqrstuvwxyz";
for($i=0;$i<$length;$i++) {
$key .= $pattern{rand(0,35)};
}
return $key;
}
$_SESSION['tmptxt'] = randomText(5);
$captcha = imagecreatefromgif("../imagenes/bgcaptcha.jpg");
$colText = imagecolorallocate($captcha, 0, 0, 0);
imagestring($captcha, 5, 16, 7, $_SESSION['tmptxt'], $colText);
header("Content-type: image/gif");
imagegif($captcha);
?>
¿Podréis ayudarme? Llevo con este problema buscando en miles de sitios más de un mes, y ya estoy desesperada.
Muchas gracias a tod@s aunque sólo sea por haberme leído