0% found this document useful (0 votes)
38 views

How To Create A PHP Contact Form

This document provides instructions on how to create a basic PHP contact form. It includes a list of materials needed, step-by-step instructions, sample source code for the HTML form and PHP script, and a reference. The instructions explain how to create an HTML form with text boxes and a submit button, write a PHP script to define email variables and send an email using mail function, and upload the files to a website to test the functioning contact form.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

How To Create A PHP Contact Form

This document provides instructions on how to create a basic PHP contact form. It includes a list of materials needed, step-by-step instructions, sample source code for the HTML form and PHP script, and a reference. The instructions explain how to create an HTML form with text boxes and a submit button, write a PHP script to define email variables and send an email using mail function, and upload the files to a website to test the functioning contact form.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

How to Create a PHP Contact Form  2008 

How to Create a PHP


Contact Form

Written by:
David Friedman

March 27, 2008


1
How to Create a PHP Contact Form  2008 

Table of Contents 
Introduction ................................................................................................ 3 
Materials Needed ........................................................................................ 3 
Instructions ................................................................................................. 3 
Source Code ................................................................................................ 4 
References .................................................................................................. 6 

2
How to Create a PHP Contact Form  2008 

Introduction
This is a supplemental manual that will assist you when viewing my tutorial on how to
create a PHP contact form. The intended audience for this tutorial is for someone who
has basic HTML and PHP knowledge. My tutorial will assist you in developing a simple
PHP contact form for your web site so that a user can send an email directly to you.

Materials Needed
ƒ Desktop computer or laptop
ƒ Internet Access
ƒ Text Editor
ƒ Web Browser
ƒ A Web Site

Instructions

1. Open text editor


a. Create a new HTML file

2. Write code for HTML contact form


a. Start with blank HTML page
b. Add labels for text boxes
c. Create text boxes
d. Create submit button

3. Open browser
a. Test to make sure the form looks correct

4. Write code for the PHP script


a. Define variables for email, subject, and message
b. Write mail function
c. Print confirmation message to the screen

3
How to Create a PHP Contact Form  2008 
5. Upload both files to your web site
a. Index.php
b. Mailform.php

6. Open browser
a. Test the mail form to make sure the email was sent

7. Check your email to make sure it worked

Source Code

1. Index.php:

“<form method='post' action='Mailform.php'>

<p>Email: <input type='text' name='email'></p>

<p>Subject: <input type='text' name='subject'></p>

<p>Message:<br/>

<textarea name='message' rows='10' cols='30'></textarea></p>

<input type='submit' value='Submit Form'>

</form>”

2. Mailform.php:

“<?php

$email_address = $_POST['email'] ;

$subject = $_POST['subject'] ;

$message = $_POST['message'] ;

mail( "[email protected]", "Subject: $subject",

$message, "From: $email" );

4
How to Create a PHP Contact Form  2008 
echo "Thank you for using our mail form.<br/>";

echo "Your email has been sent.";

?>”

Source code provided by W3Schools.com

5
How to Create a PHP Contact Form  2008 

References
ƒ W3CSchools : World Wide Web Consortium. Retrieved March 24, 2008, Web
site: http://www.w3schools.com/php/php_mail.asp (for providing the source code)

You might also like