I need a simple script for my "contact us" page, where a person could submit a blurb that would be e-mailed to me. Fields for the name, email address and a short message would be nice. I know basic HTML, so I can cut and paste mark-up with no problem. I am weak in areas of programming, PHP, etc. Actually, I am rather nervous about the prospect of a form script that would give hackers a chance to do some damage to my website. Would this kind of form pose a danger? I know I may be subjecting myself to spam, but I can always remove the script, if I get tired of the spammers. Thanks in advance.
Unless the script somehow interacts with a database backend (which a simple script obviously wouldn't) there isn't much a hacker could really do with a contact form except annoy you.
If you want a form, no one can normally hack you but spammers can annoy the heck out of you. Here is a simple scramble scrip that helps stop spammers. Just replace the areas taht say replace this with your info and it should work fine for you . When I switched from forms to this, I have not received any spam. <script language="javascript"> <!-- Hide from old browsers--> function scramble(){ var p1,p2,p3,p4,p5,p6 p1='<a href="mai' p2='front of email(replace this)' p3='">' p1+='lto:' p2+='@' p5='</a>' p6='What you want the link to say(replace this)' p2+='domain.com (replace this)' p4=p6 document.write(p1+p2+p3+p4+p5) } scramble() //--> </script>
<?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table width="600" border="0" cellspacing="0" cellpadding="2" align="center"> <tr> <td align="left"><span>Name:</span></td> <td align="left"><input type="text" name="Name"></td> </tr> <tr> <td align="left"><span>Email:</span></td> <td align="left"><input type="text" name="Email"></td> </tr> <tr> <td align="left" valign="top"><span>Message:</span></td> <td align="left"><textarea name="MsgBody" cols="40" rows="5"></textarea></td> </tr> <tr> <td align="left"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } else { error_reporting(0); $recipient = 'Change Me'; $subject = 'Change Me'; $from = stripslashes($_POST['Name']); $telno = stripslashes($_POST['TelNo']); $email = stripslashes($_POST['Email']); $company = stripslashes($_POST['Company']); $message = stripslashes($_POST['MsgBody']); $msg = "Message from: $from\n\nTelephone Number: $telno\n\nEmail: $email\n\nUsers Message:\n\n $message\n\n"; if (mail($recipient, $subject, $msg)) echo nl2br("<b>Message Sent</b>"); else echo "An unknown error occurred."; } ?> PHP: I would use this code, very good. Change the parts that say Change Me. Servii
Do a google search for dynaform.php. Its really easy, you can use whatever form fields you want, and it can send a message not only to you but also to whoever filled out the form.