June 3, 200818 yr PHP dufus alert!! I've been scouring the web for a free PHP contact form which validates as XHTML strict, but I can't find one... Anyone point me to one? Thanks
June 3, 200818 yr My mail form has an XHTML transitional doctype, but would validate as strict if you swap it for the right doctype.
June 3, 200818 yr Author My mail form has an XHTML transitional doctype, but would validate as strict if you swap it for the right doctype. Wow thanks Jem! You're a star Ultimately better than you How right you are
June 3, 200818 yr No probs - if you have any problems with it (though you shouldn't) feel free to contact me directly. I love my little tagline - draws a lot of attention
June 3, 200818 yr Author No probs - if you have any problems with it (though you shouldn't) feel free to contact me directly. I love my little tagline - draws a lot of attention OOOHhh it's beautiful!! Thank you! I'd like to take the form and use it as an includes for my website. Do I need to change the form action to _SELF or something similar, or do I need to seperate the html and PHP into separate files so that the form calls the same PHP wherever in the site it appears? If so, can you help me figure it out? Thanks again
June 3, 200818 yr You should - in theory - be able to copy the block of html with all the form bits anywhere on to a web page and as long as the action attribute points to the right place (form.php or whatever you've called the page) it will work. You'd have to remove the <?php get_data(); ?> bits from the field values though. It's probably worth mentioning I've not actually tested that myself, mind
June 3, 200818 yr Author You should - in theory - be able to copy the block of html with all the form bits anywhere on to a web page and as long as the action attribute points to the right place (form.php or whatever you've called the page) it will work. You'd have to remove the <?php get_data(); ?> bits from the field values though. It's probably worth mentioning I've not actually tested that myself, mind It works! Thanks again!
July 11, 200818 yr Does this work with SSL secure server? And is it based on Formmail or am i jus confused!
July 31, 200818 yr what about all those rude words that are in the form defined after the following: $exploits = $profanity = $spamwords = $bots = aren't they a bad thing to have within your html page - won't they get indexed by google??? Not sure i'd want all those rude words within my HTML. Any thoughts?
July 31, 200818 yr what about all those rude words that are in the form defined after the following: $exploits = $profanity = $spamwords = $bots = aren't they a bad thing to have within your html page - won't they get indexed by google??? Not sure i'd want all those rude words within my HTML. Any thoughts? That part of the form is in PHP and will never appear in the users browsers (nor in the HTML source) - it'll never be seen. Would it be possible for you to add in a Captcha, or a question "If I've got three apples, and I eat one - how many do I have left?" etc.
July 31, 200818 yr I might try this form out then - I was just a bit concerned about having all those rude words appear within the code. I need a simple small form for a site I'm doing now, so will see how this works. It would be good with a captcha - but I don't code php so not a job for me.
July 31, 200818 yr I might try this form out then - I was just a bit concerned about having all those rude words appear within the code.I need a simple small form for a site I'm doing now, so will see how this works. It would be good with a captcha - but I don't code php so not a job for me. I might have a little bash
July 31, 200818 yr I tried the form and it doesn't work... i followed the instructions and inputted my email address and web address where it said, uploaded it, filled it out and pressed send and it's been over 15 minutes and I've still not received anything...
July 31, 200818 yr I stand corrected. I got the first test email through - it took about half an hour - Anyone know why it would take so long? The second test hasn't come through at all.
July 31, 200818 yr sorry - got it working now - missed a '.' out of the email address on the last few test forms. Still not sure why the first test took so long to arrive though.
August 1, 200818 yr Hello everyone! I just discovered this forum via Google while searching for a form I could create that would be XHTML Strict-compliant. Jem, I used your free php mail-form and, although it both displays and functions correctly, when I go to check my page's validation, I get two errors. Any idea how I can fix this so the contact form returns a valid compliance? Thanks a million. ~ Jason ~ PS - This site looks fantastic, I'm so glad I found it.
August 1, 200818 yr the text area needs the width and height defined. I used: <fieldset> <legend>Required Message:</legend> <label for="comments">* Please type your message below:<br /> <textarea name="comments" id="comments" rows="6" cols="100" class="textbox"><?php get_data("comments"); ?></textarea></label><br /> </fieldset>
August 2, 200818 yr the text area needs the width and height defined. I used: <fieldset> <legend>Required Message:</legend> <label for="comments">* Please type your message below:<br /> <textarea name="comments" id="comments" rows="6" cols="100" class="textbox"><?php get_data("comments"); ?></textarea></label><br /> </fieldset> Ah, that did the trick! Thank you so much! I'm so glad I found this website
September 19, 200817 yr just a little hint about this great piece of code: i think that using preg_match instead of eregi for server validation is faster (although in this situation won't make any difference), but in the next PHP 6, eregi function will be completely removed
November 25, 200817 yr I installed this fomr on a clients website and all was fine for a few weeks but now she's getting about 20 or so spam emails through it and it's really annoying her - is there anything I can do?
November 25, 200817 yr Depends on the content of the spam. I've found that blocking "http:" usually works since there is usually a url in there... It may not suit everyone ofcourse. if (preg_match_all("/<a|http:/i", implode($_POST))) { // check for <a and http: echo "Naughty Spammer!"; exit(); }
November 25, 200817 yr some examples of the stuff she's getting throught the form are as follows: Name: Djxnhvtq Email: nzgylvhj@lnvjqskq.com Telephone: ELQATDqxdxlhB Comments: Thanks!, adult affiliate click pay per, %O, adult learning style, %P, seven of nine adult, :-PPP, active adult community napa valley, 5470, pictures of heat rash in adults, 566614, adultery coping husband, (, lack of focus adult medical condition, 9009, adult voyeur pic, 21697, adult swim lucy, 8-(, chinese adult actress, qlzbzr, adult video business, :-OO, adult only resorts in las vegas, wogulh, free adult dvd video, 80895, Submit: Send Name: Eadzahtv Email: oxswokzo@oapmirqj.com Telephone: ELQATDqxdxlhB Comments: Thanks!, adult gay spanking, 226, adult personals quality, lhh, free adult online tv, ynvf, adult escort vacation, =-DDD, ruby adult film star, %), adult flick free hardcore, slp, adult services taiwan, jytuy, number of adult tooth, =PPP, adult exercise camp, 203, adult only resorts in las vegas, batvto, adult companion holiday, >:OOO, Submit: Send Name: zihbsrbod Email: qsyfoo@dvwgaj.com Telephone: 539720788 Comments: vvxNF7 atiklmfyvfzv, qwxeqwxqbuab, [link=http://jhkocqxypgco.com/]jhkocqxypgco[/link], http://acpanniwkskr.com/ Submit: Send Lots of rude stuff but also gobbledeegook...
December 5, 200817 yr just use captcha, download any common forum / blog and use the captcha images in one of those packages.
December 8, 200817 yr just use captcha, download any common forum / blog and use the captcha images in one of those packages. I give it a try (need more practice with xhtml codes. I can't figure out why it won't validates as xhtml 1.0 strict.) php contact form with random math question. (with my sloppy codes, ) Test run Source files
December 8, 200817 yr Anyone have any ideas here. I'd really appreciate the help! Thanks E I am ever so sorry, I didn't see that this thread had been updated while I took a break from this forum! A mail form version 2 is in the works with more spam protection, but in the mean time if you want to try adding a simple question field it might help... After the form textarea, add: <label><input type="text" name="quiz" id="quiz" /> What colour is the sea?</label><br /> then change this bit: $error_msg .= "That is not a valid e-mail address. \n"; } to: $error_msg .= "That is not a valid e-mail address. \n"; } elseif (empty($_POST['quiz']) || strtolower($_POST['quiz']) != "blue") { $error_msg .= "Invalid answer to 'What colour is the sea?' \n"; } If you decide to change the question, don't forget to change "blue" to match the correct answer. (Please note, I'm at work so haven't tested this but it should work!) Edit: if anyone wants to play with version 2, you can grab it here: http://www.jemjabella.co.uk/downloads/mail_form_v2.txt but note that it's still under construction.
February 22, 200917 yr Hi all Im not sure if its because ive been working to long or that i just f---ed up but all i get when i try to view my page in a browser (Other than the xhtml) is this function clean($data) { $data = trim(stripslashes(strip_tags($data))); return $data; } // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score.. // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :) $points = (int)0; $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "****", "ejaculate", "fag", "felatio", "fellatio", "****", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur"); $exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript"); foreach ($badwords as $word) if (strpos($_POST['comments'], $word) !== false) $points += 2; foreach ($exploits as $exploit) if (strpos($_POST['comments'], $exploit) !== false) $points += 2; if (strpos($_POST['comments'], "http://") === true || strpos($_POST['comments'], "www.") === true) $points += 2; elseif (isset($_POST['nojs'])) $points += 1; elseif (preg_match("/(<.*>)/i", $_POST['comments'])) $points += 2; elseif (strlen($_POST['name']) < 3) $points += 1; elseif (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500)) $points += 2; // end score assignments if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) { $error_msg .= "Name, e-mail and comments are required fields. \n"; } elseif (strlen($_POST['name']) > 15) { $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n"; } elseif (!ereg("^[A-Za-z' -]*$", $_POST['name'])) { $error_msg .= "The name field must not contain special characters. \n"; } elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($_POST['email']))) { $error_msg .= "That is not a valid e-mail address. \n"; } elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url'])) $error_msg .= "Invalid website url."; if ($error_msg == NULL && $points <= $maxPoints) { $subject = "Automatic Form Email"; $message = "You received this e-mail message through your website: \n\n"; foreach ($_POST as $key => $val) { $message .= ucwords($key) . ": $val \r\n"; } $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n"; $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n"; $message .= 'Points: '.$points; if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { $headers = "From: $yourEmail \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } else { $headers = "From: $yourWebsite <$yourEmail> \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } if (mail($yourEmail,$subject,$message,$headers)) { echo ' Your mail was successfully sent. '; } else { echo ' Your mail could not be sent this time. '; } } } function get_data($var) { if (isset($_POST[$var])) echo htmlspecialchars($_POST[$var]); } if ($error_msg != NULL) { echo ' ERROR: '; echo nl2br($error_msg) . " "; } ?> Name: " /> E-mail: " /> Website URL: " /> Location: " /> Comments: <?php get_data("comments"); ?> All this is version 2 of the code mentioned earlier found here Version 2 I copied everything after the head tags in the script file and pasted it into the place i want the form to appear, i also changed the page file type from html to php. I have absolutly no experience with php so i cant begin to think where i could have gone wrong, any ideas anyone?
March 19, 200917 yr Dazza, if you're testing locally and you are not running a PHP server, then seeing the code (in some form or another) is expected and normal. Firefox, for example, will show the PHP as plain text in an otherwise normal HTML page. IE7 shows just code until you hit the refresh button, and then it will mimic Firefox's view. The simple expedient answer is to comment out the PHP code (use HTML comment marks) while you're testing locally. Then Firefox won't show any oddities and IE7 only needs a refresh to "look" normal, albeit with an "error on page" icon at bottom left, but that's not a concern at the testing stage. Hope that helps.
July 24, 200917 yr I am using your form and I have uploaded the form to my server and I keep getting: "Your mail could not be sent this time." I've checked everything and there's nothing that's wrong with my coding, Could it be my server not allowing it? (Free server). http://gamerzone.uuuq.com/contact.php
July 24, 200917 yr I am using your form and I have uploaded the form to my server and I keep getting: "Your mail could not be sent this time." I've checked everything and there's nothing that's wrong with my coding, Could it be my server not allowing it? (Free server). http://gamerzone.uuuq.com/contact.php Hi Adam, What host are you with? Do they allow PHP?
July 24, 200917 yr Yea they will allow php because I am using MySql queries in php files etc? I have with: www.zymic.com (my domain is uuuq.com) Thanks for the fast reply!
July 24, 200917 yr Yea they will allow php because I am using MySql queries in php files etc? I have with: www.zymic.com (my domain is uuuq.com) Thanks for the fast reply! Unfortunately, I don't think Zymic support the Mail Function on their free web hosting. You will need to contact them to enable it, which costs about $10.
July 24, 200917 yr Right do you know if that's a one off payment? I'm not even sure if I want to publish this site properly on a paid host etc. Its really just an website so I can test my skills.
July 24, 200917 yr It's a one off activation fee I believe. It's only to stop spammers signing up for free and abusing the system. If you don't want to pay the $10, have a look at a service such as this: Email me form Hope it helps!
August 1, 200917 yr Thanks for this Jem - it's a great little script Could I have a 'Thank you - message sent' message appear on the same page as the contact form rather than the form.php printing the message out seperately? I'm new to php so any help would be appreciated Cheers all.
August 25, 200917 yr Apologies for abandoning this thread again (blame pregnancy and morning sickness taking up most of my time!) There were some tweaks made to version 2 of the form a month or so ago, so anyone running an older version may wish to update (although if you're having no problems it's not urgent.)
October 6, 200916 yr Hi, I have just tried uploading this form to a site as a test, and it doesn't seem to work as it can't locate the php portion - in fact when viewing the source it doensn't even show there. This is my first dabble with PHP so I am probably doing something fundamentally wrong. I presume the whole thing needs to go in one PHP file, rather than a HTML one linking to a PHP file? I have confirmation from the host that PHP is enabled and working. Anyway here it is (without styling or anything yet): http://www.cttestarea.co.uk/Contact.php thanks
October 6, 200916 yr You need to stick the PHP code in it's own file with a .php extension.The HTML form needs to know where this file is to send the user's data, so you need to alter the form action: <form action="NAMEOFPHPFILEHERE.php" method="post">
Create an account or sign in to comment