Simple PHP Contact Form Tutorial

May 24, 2010, PHP

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.

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

grey 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
<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
<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>



, ,


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:


Subscribe

Subscribe to our e-mail newsletter to receive updates.

14 Responses to “Simple PHP Contact Form Tutorial”

  1. Wijdan Rohail Says:

    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.

    Reply

  2. geox Says:

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

    Reply

  3. Jackie Tidwell Says:

    Incredibly awesome writing! Really..

    Reply

  4. Justin Germino Says:

    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?

    Reply

  5. cna training Says:

    nice post. thanks.

    Reply

  6. chris Says:

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

    Reply

  7. forex robot Says:

    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

    Reply

  8. bharathiraja Says:

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

    Reply

  9. Sugarcane Says:

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

    Reply

  10. sham Says:

    its good ya

    Reply

  11. Theraisa K Says:

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

    Reply

  12. ranji Says:

    good post thanks for sharing it

    Reply

  13. vijai Says:

    thanks for the coding….very useful.

    Reply

Trackbacks/Pingbacks

  1. CSS Brigit | Simple PHP Contact Form Tutorial - May 29, 2010

    Simple PHP Contact Form Tutorial…

    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….

Leave a Reply

Get Adobe Flash player