HTML form:
Test Form
Username:
Email:
The file that will get the email - submit.php
submit.php contents:
<?php
$connect = mysql_connect("localhost","root","");
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
$name = $_POST['username'];
$useremail = $_POST['email'];
$to = "[email protected]";
$subject = "New user details";
$message = "Here are the details" . "
" . "Username is:". "$name" . "
" . "
" . "Email is:" . "$useremail" . "
";
mail($to,$subject,$message);
echo "Mail is sent."
?>
Some explanation
1. Usage of tables - that is to align it nicely. Try without tables
it will look messy.
2. Input type = "text" - text field, will have text box
Input name = "name" - the name of the text box. This will later
tell the submit.php file how to retrieve the details.
3. Form action = "submit.php" - the file that will grab the
details. They are all done at the server side, so the user can't
glean details. With the exception of GET method.
4. Form method = "post" - post method submit details without
revealing in the browser.
5. $name - just some variable name, can be string, can be
integer
6. $name = $_POST['username']; - if you used the POST method when
creating the submission form, you need to use the $_POST method.
Same thing for GET. It's $_GET. For a mixture, use $_REQUEST. The
string in the square brackets is the name of the field in the HTML
form.
7. mail($to,$subject,$message); - it's a mail function in
PHP.
8. echo "string here" - like printing out the results in Java or
whatever languages you know.
9. $connect - connect to the database. In this format: database
name, username, password. By default, most databases have no
password.
If you need help, refer to the documentation: http://www.php.net/manual/en/
You can set up an Apache server, MySQL and PHP with XAMPP. You can
consider XAMPP as a consolidation of the 3 open-sourced projects.
Once installed, put all your files in this directory: \htdocs
Start XAMPP, then type in localhost or 127.0.0.1 into your
browser.
Point to your file - for example, localhost/test.html and try
submitting some forms.
XAMPP by default loads all files from the htdocs directory. If you
have other projects, create a new folder and store them there. Then
point it to load this way: localhost/new project
folder/test.html
You can get XAMPP from here: http://www.apachefriends.org/en/index.html