-
|| Basic PHP Form ||
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.
HTML 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>
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 Code:
<?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
-
Nice! , I cant see any errors as far as my eye's. :D
Great Tut, Im sure many user's will use this.
Keep the tutorial Frenzy coming! ^_^
-
LOL, i will do don't worry dude, i got all these saved on my desktop to put onto my site :)
- Dan
-
I see a new Tutorial forum coming "Raremandans Tutorial's" :rolleyes:
Thank's for the new Tut :-) another one i will use :'D
-
I Forgot about my old tutorial on here ^_^ You can use that on your site if you wish Its a bit out-dated now Rofl.
http://www.habboxforum.com/showthread.php?t=79006
:D
Peace Dudes/Dudettes
-
Cheers lol :)
I'm happy writing them as long as people need them, As i love learning new things :)
- Dan
-
Very good ill be using it:) + rep:)
Edit: Iam very sorry but it says "You must spread some Reputation around before giving it to Raremandan again." sorry:(
-
To check if a variable is empty its better to use:
PHP Code:
if (!$post) {
echo "You havent filled in this field";
}
also why do you keep ending the <? ?> tags :S to write something just use echo :P Its abit long winded but well construced.
Instead of using a meta redirection the easier way in php is to do:
PHP Code:
header("Location: formsent.php");
-
Just what i needed
But the test email thingys are taking ages to come >:l
-