el contacto.php
Código :
// QUINTI.NET SECURE FORM VERSION 1.0 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="shortcut icon" href="image.gif" type="image/x-icon" /> <title>Quinti.net - Contact form example web secure anti spam with captcha</title> //U NEED A PHP SERVER. //START REQUIRED IN HEAD <? // Quinti.net - Secure Contact Form Antispam with CAPTCHA v1.0 // Created by Jesus Quintana // http://www.quinti.net // Visit site for help and new versions echo "<script type=\"text/javascript\">\n"; echo "<!--\n"; echo "function validar(form1) {\n"; echo "if (form1.name.value.length < 2) {\n"; echo "alert('"; echo "Inserte el nombre";; echo "')\n"; echo "form1.name.focus();\n"; echo "return (false);}\n"; echo "var checkOK = \"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ\" + \"abcdefghijklmnñopqrstuvwxyzáéíóú \";\n"; echo "var checkStr = form1.name.value;\n"; echo "var allValid = true;\n"; echo "var uword = hex_md5(document.getElementById('uword').value)\n"; echo "for (i = 0; i < checkStr.length; i++) {"; echo "ch = checkStr.charAt(i);\n"; echo "for (j = 0; j < checkOK.length; j++)\n"; echo "if (ch == checkOK.charAt(j))\n"; echo "break;\n"; echo "if (j == checkOK.length) {\n"; echo "allValid = false;\n"; echo "break;"; echo "}}\n"; echo "if (!allValid) {\n"; echo "alert('"; echo "Inser a name"; echo "');\n"; echo "form1.name.focus();\n"; echo "return (false);}\n"; echo "if ((form1.email.value.indexOf ('@', 0) == -1)||(form1.email.value.length < 9) || form1.email.value.indexOf ('.', 0)== -1 ){\n"; echo "alert('"; echo "Insert a valid email "; echo "');\n"; echo "form1.email.focus();"; echo "return (false);}\n"; echo "if (form1.message.value.length < 7) {\n"; echo "alert('"; echo "Insert a message"; echo "');\n"; echo "form1.message.focus();"; echo "return (false);}\n"; echo "if (uword==cword[anum-1]) {\n"; echo "return true;}\n"; echo "else {\n"; echo "alert('"; echo "Insert image code (is to prevent spam) "; echo "');\n"; echo "document.getElementById('uword').focus();\n"; echo "return false;}\n"; echo "return (true);}\n"; echo "-->\n"; echo "</script>\n"; ?> <script type="text/javascript" src="md5.js"></script> <script type="text/javascript" src="jcap.js"></script> //END REQUIRED IN HEAD <style type="text/css"> <!-- img{border:0;} --> </style> </head> <body> //START REQUIRED IN BODY <form method="post" onsubmit="return validar(this)" id="form1" action="gracias.php"> <p> <input type="hidden" name="token" value="<?=$token?>" /> </p> <p> Nombre:*<input name="name" type="text" value="" /> </p> <p> E-mail:* <input name="email" type="text" value="" /> </p> <p> Asunto: <input name="phone" type="text" value="" /> </p> <p> Mensaje:* <br /> <textarea name="message" cols="30" rows="5"></textarea> </p> <p> Insert the image code* (to prevent spam)</p> <p><input type="text" name="uword" id="uword" value="" /> </p> <p><script type="text/javascript">cimg()</script> </p> <p> <input type="submit" value="enviar" /> </p> </form> <p>fields with * are obligatory. <a href="http://www.quinti.net" title="www.quinti.net - diseño web y multimedia"><img src="http://www.quinti.net/pics/q.png" width="21" height="14" alt="diseño web y multimedia" /></a></p> //END REQUIRED IN BODY <p> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1" height="31" width="88" /></a> </p> </body> </html>
Y el gracias.php
Código :
// QUINTI.NET SECURE FORM VERSION 1.0 //START REQUIRED CODE <? // Quinti.net - Secure Contact Form Antispam with CAPTCHA v1.0 // Created by Jesus Quintana // http://www.quinti.net // Visit site for help and new versions @import_request_variables("gpc");//import variables $youremail = "[email protected] "; //your mail $subject = "el título del tema "; // for example, title of your contact page page - contact $redirect = "contacto.php";//url to be redirected when contact form is sent $secs = "5";// time in seconds will be redirected if(eregi("MIME-Version:",$postVars)) { mail("[email protected]", "Form Hijack Attempt", "A spam relay was attempted from the Web site and was blocked.", "From:SpamMonitor"); die(); } //block spam $secret = 'ssshhitsasecret'; $token = md5(rand(1, 1000).$secret); $_SESSION['token'] = $token; ?> //END REQUIRED CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" > <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" /> <title> Thank you, processor example anti spam with captcha by quinti.net, correct process</title> //START REQUIRED META <meta http-equiv="refresh" content="<?=$secs;?>;URL=<?=$redirect;?>" /> //END REQUIRED META </head> <body> //START REQUIRED IN BODY <? // variables to stop spammers $name = stripslashes($name); $message = stripslashes($message); $headers .= "From: " . $email . "\r\n\r\n"; //This is where the email is sent using your values from above. Be sure to update this if you change any fields in contact.php mail("$youremail", "$subject"," Name: $name Email: $email Phone: $phone Message: $message ",$headers); // Strip \r and \n from the email address $_POST['email'] = preg_replace("\r", "", $_POST['email']); $_POST['email'] = preg_replace("\n", "", $_POST['email']); $_SESSION['token'] = $token; $token = md5(rand(1, 1000).$secret); $secret = 'ssshhitsasecret'; $field = preg_replace( "/[\n\r]+/", " ", $field ); // Remove injected headers $find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i"); $_POST['email'] = preg_replace($find, "", $_POST['email']); $message = preg_replace($find, "", message); $email=str_replace("\r","\n",$email); $name=str_replace("\r","\n",$name); $message=str_replace("\r","\n",$message); $phone=str_replace("\r","\n",$phone); if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { ob_clean(); mail("$youremail", "Message Killed", "$message", "From: $name <$email>"); exit("Message killed."); } if (eregi('^(bcc$|content-type|mime-version|--)',$key)) print_error("Field names indicate exploit."); //bloqueo de spam ?> <p>Thank you, the contact form was sent correctly. In 5 seconds you will be redirected to index page.</p> //END REQUIRED IN BODY </body> </html>