What techniques are available for sending an email via a webpage or a form on a webpage?
I’ve got some background idea that you POST the form data to a script but I’ve don’t really know what a cgi script is (I’d love to learn if this is the suggested method!) or what the current practice is.
This is just to provide some way for users to contact the operators. The in-page form seems like it would be easier on the user than ask them to open their mail client. I was also concerned about bots harvesting the contact email address (in the case of mailto: links).
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
$_POSTarray, the<input name=''>becomes the arrays index.. For example..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():You would just set
$toto your email address (Do not allow the user to set this, or they are able to send mail as ‘you’, to anyone – ‘spam’..),$subjectand$messagewould be set form$_POST[]Before you go any have a HTML file that goes to a script with
mail('me@example.com', $_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)!