When you submit a form, the data in that form gets sent to the server-side script. For example, in PHP you access that data with the $_POST
array, the <input name="">
becomes the arrays index.. For example..
// <form action="mailer.php">[..]<input name="subject" [..]><input name="content" [..]></form>
echo("The subject is: ". $_POST['subject']);
echo("The content is:" . $_POST['content']);
At the most basic level, all you have to do is use your programming languages built in mail function. Again, in PHP this is simple mail()
:
mail($to, $subject, $message);
You would just set $to
to your email address (Do not allow the user to set this, or they are able to send mail as "you", to anyone - "spam"..), $subject
and $message
would be set form $_POST[]
Before you go any have a HTML file that goes to a script with mail("[email protected]", $_POST['subject'], $_POST['content']);
, think what would happen if someone reloaded that page 200 times.. You must have some kind of security in it, probably a captcha, and/or rate-limiting.
One thing, that has bugged me before - remember a "contact us form" is not a replacement for giving an actual email address! For example, my mail client keeps a copy of all mail I send, and I can attach files, and it's much nicer writing in a familiar mail client than a form <textarea>
(especially when the I accidently hit "back" and the form decides to clear itself)!