Hello John John.
Here is a good introduction to PHP (in my opinion)
How to create
1. an e-mail form that posts to a php file, and
2. the php file that e-mails you the info then sends the info to a MySQL database, and
3. the MySQL database
copy the lines below to a text editor and save as "processform.php"
/*
Beginning of long comment
The sytax above (slash then asterisk) indicates that you are starting
a very long comment. The reverse (asterisk then slash) indicates the end.
Copy and paste this file into a text editor and name it "processform.php".
Look at the comment lines starting with a pound sign (#) and make changes
to the lines below.
The double slashes are comments explaining what is about to take place below.
A. Create an HTML form using the code below:
<HEAD>
<TITLE>E-Mail Form</TITLE>
</HEAD>
<BODY>
<FORM method="POST" action="processform.php">
<P>Your Name:<br>
<INPUT type="text" name="sender_name" size=30>
</p>
<P>Your E-Mail Address:<br>
<INPUT type="text" name="sender_email" size=30>
</p>
<P>Your Telephone Number:<br>
<input type="text" name="sender_phone" size=30>
</p>
<P>
<INPUT type="submit" value="Send This Form">
</p>
</FORM>
</BODY>
B. Create a MySQL database table.
Step 1. Go to http://phpmyadmin.sourceforge.net and download the "phpMyAdmin" program
Step 2. Open the config.inc.php3 file and configure it to your web hosting company settings
You will need to know the following (ask your web hosting company or review documentation)
a. hostname (usually "localhost")
b. database name
c. username
d. password
Step 3. Upload the entire folder of "phpMyAdmin" to your web server.
It is important to password protect this folder so that
no one can have access to your database by typing http://www.yourdomain.com/phpMyAdmin
Step 4. Once you have uploaded the phpMyAdmin folder, access it on the web
by typing http://www.whateveryourdomainis.com/phpMyAdmin (case sensitive)
Step 5. create a database table. The database(s) will be located on the left.
You need to create a table by copying the following 6 lines and pasting them into the
Run/SQL queries window:
CREATE TABLE formdata (
sender_name varchar(25) NOT NULL,
sender_email varchar(25) NOT NULL,
sender_phone varchar(12) DEFAULT '0' NOT NULL,
ID int(11) DEFAULT '0' NOT NULL auto_increment,
PRIMARY KEY (ID));
The above lines will create a table named "form data". We will insert the data
from your HTML form "form.html"
Here is the code that takes the following fields (sender_name, sender_email, sender_phone, message) from a form and
- mails you a notice
- sends the information (name, email and phone) to a database:
End of Long Comment
*/
//The line below signifies the beginning of a PHP file.
<?php
//Process information from HTML Form in Order to Send E-mail
if ($sender_email and $message)
{
//Concatenate (breaking up a long command into 4 different lines
$msg = "Sender Name:\t$sender_name\n";
$msg .= "Sender E-Mail:\t$sender_email\n";
$msg .= "Sender Telephone:\t$sender_phone\n\n";
$msg .= "Message:\t$message\n\n";
change the line below to your e-mail address
$recipient = "you@yourdomain.com";
$subject = "Web Site Feedback";
$mailheaders = "From: My Web Site <> \n";
$mailheaders .= "Reply-To: $sender_email\n\n";
//The command below is what sends the e-mail
mail($recipient, $subject, $msg, $mailheaders);
//Send message to Sender that the Form was sent successfully
echo "<HEAD><TITLE>Form Sent!
</TITLE></HEAD><BODY>";
echo "<H1 align=center>Thank You, $sender_name</H1>";
echo "<P align=center>Your feedback has been sent.</P>";
echo "</BODY>";
} else {
//A screen message to those who did not complete the HTML Form correctly
echo "<HEAD><TITLE>Form empty!
</TITLE></HEAD><BODY>";
echo "<H1 align=center>There is no email address or message body.</H1>";
echo "<P align=center>Please go back and make sure you have entered an email address and a message body</P>";
echo "</BODY>";
}
//Let's connect to the database now and insert the values
Let's change the information below
$hostname="???"; #this value is usually "localhost" get this value from web hosting company
$username="???"; #get this value from your web hosting company
$password="???"; #get this value from your web hosting company
$database="???"; #get this value from your web hosting company
// The name of the MySQL table created above has 4 fields
$usertable="formdata";
/ Name of fields in the table: sender_name, sender_email, sender_phone, ID /
//Connect to server with username and password
MYSQL_CONNECT($hostname, $username, $password)
or die ("Could not connect");
print ("Connected to host successfully");
//Now Connect to database
@mysql_select_db ("$database")
or die ("***Could not connect to database");
print (" --Connected to database successfully");
//Primary Key, ID, set to auto increment, will not need to be passed to the database
//Send data (pass values) to the database
$query="INSERT INTO $usertable (sender_name, sender_email, sender_phone)
VALUES('$sender_name','$sender_email','$sender_phone')";
$result=MYSQL_QUERY($query);
//close the database connection//
MYSQL_CLOSE();
//That should do it!!!
?>