Simple PHP Contact Form Tutorial

Posted May 24th, 2010 by

When you need that user contact with you or send feedback to you via email then you have to need make a contact form. In this tutorial you will learn that how to create form with php script.

Helpful Links


Overview

In this tutorial create 2 files 1. contact.php and 2. send_contact.php

Step
1. Create file contact.php.
2. Create file send_contact.php.

Step1:

Create file contact.php

contact form Simple PHP Contact Form Tutorial
View In Browser

|—|——————— code ——————–|—|

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<p><table
  width="400" border="0" align="center" cellpadding="3"
  cellspacing="1"><br>
  <tr><br>
  <td><strong>Contact Form </strong></td><br>
  </tr><br>
  </table></p>
<p><table
  width="400" border="0" align="center" cellpadding="0"
  cellspacing="1"><br>
  <tr><br>
  <td><form name="form1" method="post"
  action="send_contact.php"><br>
  <table width="100%" border="0" cellspacing="1" cellpadding="3"><br>
  <tr><br>
  <td width="16%">Subject</td><br>
  <td width="2%">:</td><br>
  <td width="82%"><input name="subject" type="text"
  id="subject" size="50"></td><br>
  </tr><br>
  <tr><br>
  <td>Detail</td><br>
  <td>:</td><br>
  <td><textarea name="detail" cols="50" rows="4"
  id="detail"></textarea></td><br>
  </tr><br>
  <tr><br>
  <td>Name</td><br>
  <td>:</td><br>
  <td><input name="name" type="text" id="name"
  size="50"></td><br>
  </tr><br>
  <tr><br>
  <td>Email</td><br>
  <td>:</td><br>
  <td><input name="customer_mail" type="text"
  id="customer_mail" size="50"></td><br>
  </tr><br>
  <tr><br>
  <td> </td><br>
  <td> </td><br>
  <td><input type="submit" name="Submit" value="Submit">
  <input type="reset" name="Submit2" value="Reset"></td><br>
  </tr><br>
  </table><br>
  </form><br>
  </td><br>
  </tr><br>
  </table></p>

Step2:

Create file send_contact.php

|—|——————— code ——————–|—|

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<p><?php<br>
// Contact subject<br>
  $subject ="$subject"; <br>
// Details<br>
$message="$detail"; </p>
<p>// Mail of sender<br>
  $mail_from="$customer_mail"; <br>
// From <br>
  $header="from:
  $name <$mail_from>"; </p>
<p>// Enter your email address<br>
  $to ='someone@somewhere.com'; </p>
<p>$send_contact=mail($to,$subject,$message,$header);</p>
<p>// Check, if  message sent to your email <br>
"We've recived your information"<br>
if($send_contact){<br>
echo "We've recived your contact information";<br>
}<br>
else {<br>
echo "ERROR";<br>
}<br>
?></p>


Random Posts

Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, or follow us on Twitter. Get promotion with Hypesol.
Name: Email:
13 ResponsesLeave a comment
  • Wijdan Rohail
    May 24, 2010 at 11:20 pm
    Reply

    WOW, thats really great and impressive. It is very useful and thanks a lot for providing such a great coding, I was searching this coding since last few months.

  • geox
    May 25, 2010 at 11:11 pm
    Reply

    It’s real good,i think i will bookmark this page.Thanks

  • Jackie Tidwell
    May 27, 2010 at 4:24 pm
    Reply

    Incredibly awesome writing! Really..

  • Justin Germino
    May 30, 2010 at 9:16 am
    Reply

    Really simple to do and easy, really like the way you lay out exactly what to cut and paste in each file. Does the sender use the default sendmail of the hosting provider, is there any way to configure a custom “email SMTP” to send from?

  • cna training
    May 31, 2010 at 8:02 pm
    Reply

    nice post. thanks.

  • chris
    June 1, 2010 at 12:40 pm
    Reply

    This a nice tut, but it needs adding to to make it secure and to validate input, I would not use this live atm.

  • forex robot
    June 15, 2010 at 9:55 pm
    Reply

    found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later

  • bharathiraja
    August 9, 2010 at 3:20 am
    Reply

    itz nice.. but your not mentioning about the header file……

  • Sugarcane
    October 12, 2010 at 4:55 am
    Reply

    Brilliant stuff, I’m trying to learn PHP right now and these tutorials are invaluable

  • sham
    October 14, 2010 at 4:47 am
    Reply

    its good ya

  • Theraisa K
    March 31, 2011 at 12:37 pm
    Reply

    How would you go about validating this? I mean, what would the script look like?

  • ranji
    August 26, 2011 at 11:25 pm
    Reply

    good post thanks for sharing it

Add a commentGet a Gravatar

* Name

* Email Address

Website Address

You can usethese tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



  •  
  •  
  •  
Around The Site
Free Subscription

Enter your email address:

 
Become Facebook Fan
Links
Get Adobe Flash playerPlugin by wpburn.com wordpress themes