Dan Williamson
21-11-2005, 11:10 AM
Hi.
For my second PHP tutorial i'm going to tell you how to code a simple form with a simple PHP code.
This tutorial is written and copyright to me :)
Here we go:
Well first the easy bit.
Creating the forms layout. and here we go.
<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>
Now i'm sure your all familiar with a simple form layout so i kept it simple.
Now you must name the PHP file mail.php if you don't want to change anything on the form layout.
Heres the PHP code i'll explain in the PHP code so it doesn't get confusing.
<?php
//variables (You can change the Variables)
$youremail = "[email protected]";
// your email address
$subject = "Contact";
// the subject of the email
$formsent = "formsent.php";
// The re-direct page in which it can say Form sent
// Don't change anything else on this script
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 $formsent;?>"">
<?php
}
?>
Now the bits with // are explaining what to do, after reading many PHP tutorials for CMS's i've seen people do this.
I took around 20 minutes last night creating this form as i ran into a few problems, this should work if not please contact me :)
- Dan
For my second PHP tutorial i'm going to tell you how to code a simple form with a simple PHP code.
This tutorial is written and copyright to me :)
Here we go:
Well first the easy bit.
Creating the forms layout. and here we go.
<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>
Now i'm sure your all familiar with a simple form layout so i kept it simple.
Now you must name the PHP file mail.php if you don't want to change anything on the form layout.
Heres the PHP code i'll explain in the PHP code so it doesn't get confusing.
<?php
//variables (You can change the Variables)
$youremail = "[email protected]";
// your email address
$subject = "Contact";
// the subject of the email
$formsent = "formsent.php";
// The re-direct page in which it can say Form sent
// Don't change anything else on this script
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 $formsent;?>"">
<?php
}
?>
Now the bits with // are explaining what to do, after reading many PHP tutorials for CMS's i've seen people do this.
I took around 20 minutes last night creating this form as i ran into a few problems, this should work if not please contact me :)
- Dan