Tutorial Related Links
If you wish to view a full list of all the tutorials that have been posted by Tony Bob Design
or wish to browse our arhives, click on the links above.
Categories
If you wish to browse our tutorials by category, navigate with the links above.
Tutorials - php - Contact Form
Posted by:Tony Bob on Sep 14 2006
mail.php
Step 1
Open a text editor like Notepad and copy/paste the following and save it as mail.php:
Code
<?php//variables (change these)
$youremail = "name@domain.com";
// your email address
$subject = "Contact";
// the subject of the email
$thankyou = "thankyou.php";
// thank you page
// don't change anything else
if($email == ""){
?>
No email address added. Please go back.<br/>
<?php
}elseif($name == ""){
?>
No name added. Please go back.<br/>
<?php
}elseif($message == ""){
?>
No message added. Please go back.<br/>
<?php
}else{
$msg = ereg_replace("\\\'", "'", $message);
$msg = ereg_replace('\\\"', "\"", $msg);
$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";
mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
?>
<meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">
<?php
}
?>
The Form
Step 2
Now for the form:
Code
<form action="mail.php" method="post">Name <input type="text" name="name"><br/>
Email addess <input type="text" name="email"><br/>
Message<br/>
<textarea name="message" cols="40" rows="5"></textarea><br/>
<input type="submit" value="send"><br/>
</form>
And thats it! You should have a simple contact form fully working.
Rate This Tutorial
Comments
Add A comment










