Cool PHP Contact Us!


Here you will make a simple but effective PHP Contact Us!

Here Is The Script With Explanation

Add this to your config.php
PHP Code
  1. function cleanvars($content){ //declare the cleanvars function
  2. $content = mysql_real_escape_string($content);
  3. $content = strip_tags($content); //strip html code
  4. $content = addslashes($content); //addslashes to protect from possible SQL Injection
  5. return $content; //return new content
  6. } //end function


PHP Code
  1. <?php
  2. echo 'Contact Us'; //Title Goes Here
  3. if(isset($_POST['contact'])) //if the form is posted
  4. {
  5. $name = cleanvars($_POST['name']); //These Check to see if the posts from the form are empty
  6. $email = cleanvars($_POST['email']);
  7. $subject = cleanvars($_POST['subject']);
  8. $message = cleanvars($_POST['message']);
  9. if(!isset($name))
  10. {
  11. echo 'Please enter your name'; //if there is no name in the form it displays the message
  12. }
  13. elseif(!isset($email))
  14. {
  15. echo 'Please enter your email'; //if there is no email in the form in the form it displays the message
  16. }
  17. elseif(!isset($subject))
  18. {
  19. echo 'Please enter the subject'; //if there is no subject in the form in the form it displays the message
  20. }
  21. elseif(!isset($message))
  22. {
  23. echo 'Please enter your message'; //if there is no message in the form in the form it displays the message
  24. }
  25. elseif($code = $_SESSION['key'])
  26. { } else {
  27. mail('YOUR EMAIL GOES HERE', $subject, $message, 'FROM:'.$email); //the email that it will be sent to goes here, this also sends the email
  28. echo 'Mail sent'; //This Message Shows Once The Message Is Sent Sucessfully.
  29. }
  30. }
  31. else
  32. {
  33. echo '
  34. <center>
  35. <form method="post">
  36. <table width="80%" border="0">
  37. <tr>
  38. <td width="30%"><b>Your Name</b></td>
  39. <td width="70%"><input type="text" id="text_edit" name="name" /></td>
  40. </tr>
  41. <tr>
  42. <td width="30%"><b>Your Email</b></td>
  43. <td width="70%"><input type="text" id="text_edit" name="email" /></td>
  44. </tr>
  45. <tr>
  46. <td width="30%"><b>Subject</b></td>
  47. <td width="70%"><input type="text" id="text_edit" name="subject" /></td>
  48. </tr>
  49. <tr>
  50. <td width="30%"><b>Message</b></td>
  51. <td width="70%"><textarea id="text_edit" name="message"></textarea></td>
  52. </tr>
  53. <tr>
  54. <td width="30%"></td>
  55. <td width="70%"><input type="submit" name="contact" id="text_edit" value="Contact Us" /></td>
  56. </tr>
  57. </table>
  58. </form>
  59. </center>'; //This Is A Simple PHP HTML Form, No Need For Explaining If You Need Explaining Just Send Me A Message
  60.  
  61. }
  62. echo '</div>';
  63. ?>

If You Need Help Just Ask!
Liquidsteel's Avatar
Views:
3,337
Rating:
Posted on Sunday 4th May 2008 at 12:50 PM
ShadowMage
ShadowMage's Avatar
Added a different cleanvars function then what he probably has but hey, it should work =)
Posted on Sunday 2nd December 2007 at 05:04 PM
cyruswu
cyruswu's Avatar
Remove cleanvars who needs cleanvars.

It's not eve na defined function. Get rid of it.
Posted on Friday 16th November 2007 at 03:47 AM
-=InSaNe=-
-=InSaNe=-'s Avatar
Allready put that in. I dont have a free host, dont worry.
Posted on Thursday 15th November 2007 at 07:59 PM
darklight19
darklight19's Avatar
You may also want to log IP's too.
Posted on Thursday 15th November 2007 at 07:58 PM
darklight19
darklight19's Avatar
without bot verification someone can spam you and use your email send limit. Most free host are set to about 400-500 emails. If you go above that you can get a fine, or get shut down. 110mb.com is this way, I think they fine you $2,000. So make sure you use bot verification before using this. If you don't know how to do that look at this tutorial (https://www.visualbuilder.com/viewpages.php?art_id=1286&pageorder=1)
Posted on Wednesday 14th November 2007 at 08:13 PM
ShadowMage
ShadowMage's Avatar
You will need to add bot verification so you dont get spammed. xD
Posted on Wednesday 14th November 2007 at 05:47 PM
DanielXP
DanielXP's Avatar
It works for Liquidstell because he has the cleanvars() function.

You could add it your self or remove the cleanvars(.....)

Liquidsteel: Send a email with the cleanvars function to us. Subject: "TM265"
Posted on Wednesday 14th November 2007 at 03:16 PM
-=InSaNe=-
-=InSaNe=-'s Avatar
To lazy to fix it. Still does not work :S
Posted on Wednesday 14th November 2007 at 03:33 AM
Liquidsteel
Liquidsteel's Avatar
:S it works for me. :P
Posted on Wednesday 14th November 2007 at 12:31 AM
-=InSaNe=-
-=InSaNe=-'s Avatar
Fatal error: Call to undefined function cleanvars() in /home/wehabbon/public_html/mehleclan/TheTestPage.php on line 5

To lazy to figure out error :D I will look into it lator.