PHP(PHP Contact form)>>

It is not a good idea to place a contact email in your web. Someone may use a robot to find your email and send spam. Instead, it is recommended to use a contact form.

You will find bellow a copy and paste contact form. You just need to copy the code to a file named contact_form.php, change emails in red, and place it in your site. Them add a link to the contact form in your regular pages.

 

contact_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<html><head><title>Contact Form</title></head>
<body bgcolor=FFFFFF>

<center><p><center>
<H1>Suggestions/Questions about mysite.com</h1>
<table><tr><td>

<?
$text=$_POST["text"];
$email=strtolower($_POST["email"]);
if (strpos($email,"@")==0 or strpos($email,".")==0){$email="";}
if ($email!="" and $text!=""){
   $message="$email\n\n$text";
   mail("webmaster@mysite.com","Contact form", $message,"From: <webmaster@mysite.com>\nContent-Type: text/plain");
   print "<center>Thanks for your Suggestion/Question<p><a href=/>Home Page</a></center>";
}else{
?>

<form action=contact_form.php method=post>
<p>Your contact email:<br>
<INPUT NAME="email" SIZE="35" MAXLENGTH="65">
<BR>Your text:<br><TEXTAREA name=text cols=40 rows=5><? print $text; ?></TEXTAREA>
<br><INPUT TYPE="SUBMIT" NAME=submit VALUE=Submit>
</form>

<? } ?>

</td></tr></table>
</center></body></html>

Lines 1-6: Just page title and headings

Lines 8-17: php code

Line 9: Text introduced by user is saved to variable $text.
Line 10: email is saved to variable $email. By using strtolower, we will get the email in lower case.
Line 11: It is checked whether email is correct (simple checking). The command strpos is used to check position of "@" and "." within $email. If position is "0", $email is not correct and email information is removed (is set to "").
Line 12: If value of $email or $text is not null, lines 13 to 15 are executed. If not, the form in lines 20-25 is displayed.
Line 13: A new variable named is created which contects the email value and text of user. The code "\n\n" means we are separating email and text with two line breaks.
Line 14: The command mail is used to send email.
Line 15: A "Thanks you" message is shown.

Lines 20-25: If message is not send (for example when getting to the page from a link), the form is displayed.

Line 23: In case a user has introduced a message in the textbox, but has forgotten to include email, as $email="", mail is not send to webmaster, and the form is displayed. In this case, the code "<? print $text; ?>" is used to include the message in the textbox.

<< Back








   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006-2010 All Rights Reserved By CodeDcode.Com : HTML : RSS : TEXT : XML