Create a Contact Page with HTML and PHP

Contact Form

Final result: HERE

I have made a tutorial about how to install EasyPhp and now i come with an example. Today we learn how to create a
Contact Page in HTML and PHP very easy! Download the next files to exercise on them:

bg.gif
index.php
send.php

Download: HERE

[1] Let’s write the index.php /  Here we use HTML

<html>
<head>
<title>Contact</title>
</head>
<body>
<body background=”bg.gif”>
<form action=”send.php” method=”post”>
<pre>
<center>
<br>
<br>
E-Mail
<input type=”text” name=”email” value=”"><br>
Name
<input type=”text” name=”name” value=”"><br>
Surname
<input type=”text” name=”surname” value=”"><br>
Subject
<input type=”text” name=”subject” value=”"><br>
Message<br>
<textarea name=”message” cols=”60″ rows=”6″></textarea><br><br>
<input type=”submit” name=”Send” value=”Send”><input type=”reset” name=”Clear” value=”Clear”>
</form>
</body>
</html>

Save this like index.php

[2] Here we write the send.php page

<?php
if(($_POST['email'] == ”) || ($_POST['name'] == ”) || (is_numeric($_POST['name'])) || ($_POST['surname'] == ”) || (is_numeric($_POST['surname'])) || ($_POST['subject'] == ”) || ($_POST['message'] == ”)) {
echo ‘Complete the forms correctly <br>
Click <a href=”index.php” mce_href=”index.php”>here</a> to return on main page.’;
} else {
$to = ‘piticstyle@yahoo.com’; // change e-mail adress
$send_date = date(’d-m-Y H:i:s’);
$subject = $_POST['subject'];
$message = ‘
<html>
<head>
<title>Contact</title>
</head>
<body>
<p><tt>Send Date: ‘.$send_date.’ </tt></p>
<table>
<tr>
<td><tt> Name: ‘.$_POST['name'].’ </tt></td>
</tr>
<tr>
<td><tt> Surname: ‘.$_POST['surname'].’ </tt></td>
</tr>
<tr>
<td><tt> E-Mail: <a href=”mailto:’.$_POST['email'].’” mce_href=”mailto:’.$_POST['email'].’”>’.$_POST['email'].’</a> </tt></td>
</tr>
<tr>
<td><tt> Message: <br><br> ‘.$_POST['message'].’ </tt></td>
</tr>
</table>
</body>
</html>’;
$headere = “MIME-Version: 1.0\r\n”;
$headere .= “Content-type: text/html; charset=iso-8859-1\r\n”;
$headere .= “From: “.$_POST['name'].” “.$_POST['surname'].”<”.$_POST['email'].”>\r\n”;
mail($to, $subject, $message, $headere);
echo ‘The message was send’;
}
?>

Save this like send.php

[3] Test your contact page:

To test your contact page you need to upload the files on a server. If you dont have your own server & domain name, search on internet websites who give free host with the option to have acces on the ftp. I found a site:

Yeahost.com

If you don’t understand something please write a comment, thank you for your attention and check this tutorial to learn how to install EasyPHP (Php, MySQL, Apache, PhpMyAdmin). Here is the final result

Tags: , , , , , , , , , ,

5 Responses to “Create a Contact Page with HTML and PHP”

  1. nookli » Blog Archive » Create a Contact Page with HTML and PHP Says:

    [...] here This entry was posted on Friday, October 26th, 2007 at 7:17 pm and is filed under php download. [...]

  2. John Says:

    Hi
    Thanks for the code, I upload the desired forms, but when i send the forms i didnt received any email.
    please tell me what should I do now.
    Best regards
    john

  3. PiticStyle Says:

    John, you need to change te email adress and the pages will need to be with the PHP extension!

  4. John Says:

    Thanks for reply,
    I also did that change but again i didnt received email.
    thanks

  5. irfan Says:

    Thank u very much John for your such a wonderful tutorial but please tell me one thing that how we will save the link and how we hyperlink the flash forum with php or html coding?

Leave a Reply