If there are any errors, please notice me, IŽve translated it from Norwegian, and some variables or other stuff might be wrong.
<form action="send.php" method="post" enctype="multipart/form-data"> Name:<br /> <input type="input" name="name"><br /> Mail: <br /> <input type="input" name="mail"><br /> Subject: <br /> <input type="input" name="subject"><br /> Message: <br /> <textarea name="message" rows="8" cols="55"></textarea><br /> <input name="submit" type=submit value="Send mail"> <input name="reset" type=reset value="Reset"> </form>
Ok, this is our form, just insert it wherever you want to on your page. It tells the user to insert name, mail, subject and message. Save the file as mail.php or whatever.
Now, on to send.php, the file that does it all (PS: If you choose not to call it send.php, you must change the form action)
<?php if ($_POST[name] && $_POST[mail] && $_POST[subject] && $_POST[message]) { $name = stripslashes($_POST[name]); $subject = stripslashes($_POST[subject]); $mail = stripslashes($_POST[mail]); $message = stripslashes($_POST[message]); $date = date("d.m.Y"); // Sets dateformat. This one prints ex: 02.12.2005 $ip = $_SERVER['REMOTE_ADDR']; // Gets the users IP address $headers = "From: $name"; $sendto = "[email protected]"; // The mail will be sent to this adress, so if you want to receive the mail, you should change this to your own;) $subject = "$subject"; $message = // The layout of our message "------------------------------------------------------------------------------------------ Mail sent from (YOUR WEBPAGE) ------------------------------------------------------------------------------------------ Subject: $subject Sent: $date From: $name $nameŽs mail: $mail $nameŽs ip: $ip ------------------------------------------------------------------------------------------ Message: $message ------------------------------------------------------------------------------------------ Autogenerated mail from (YOUR WEBPAGE) Copyright Indigo 2005"; if (mail($sendto, $subject, $message, $headers)) { echo "Your mail has been sent";} else echo "Raaah, something went wrong! CouldnŽt send mail";} else { echo 'Raaah, something went wrong! Make sure you fill out all the fields. All fields are required.'; } ?>
For somebody, this is simple, for others this might be hard. IŽll try to explain some of it:
stripslashes - Makes sure the message, name or the other fields does not contain HTML-code, as this might crash our site or something (which is bad)
By the way: Sorry for language errors, my English really sucks
Also, I wasnŽt sure if this is good enough for Twodded or anything (actually I doubt it), but if you think, tell me:)
If you choose to use this script at your page, IŽd appreciated if you let me know:)