How To Use SendMail In Your Web Site Forms
SendMail is an external program which allows you to send email from within
a Perl script. This is useful for sending email from a web form, results of
surveys and quizzes, and other useful applications. This document will give you
an example of how to use SendMail in your perl script. This is not a
method for beginners to use. If you are looking for an easy way to send mail
from your web site, please see
Using Form Mail For Visitor Feedback E-Mail.
The code in this document is very basic. It is up to you to add any security
features necessary to prevent abuse of your script. Active Web Hosting will
shut down any domain that is being used to send spam.
Using SendMail In The Perl Script
First you'll want to create a perl script that your web site forms can use to send the mail. Below is example code you can use to build your script. You will need to alter the script to suit your own needs for it to work. Save your final script in a subdirectory on your CGI server, and set the file permissions to 755. For this example, we'll use sendmailform.cgi for the filename.
Creating the Web Form
When you create the web form, be sure that the form action points to your script file. You can use the code below as an example to build your web form. Change the highlighted areas to suit your needs.
Finishing The Project
All that is left to do is make a thanks.html file which visitors will be directed to after submitting the email form. Do note that there are "hidden" areas in the form, which are then passed and used in the script. Careful study of the examples above will give you a good idea how SendMail works from within a Perl script.
Can I have my visitors send file attachments?
It is possible for visitors to send you file attachments from your web form. However, we will not cover this process here. Due to the constant threat of spam and viruses, extra care should be taken when allowing visitors to send file attachments. We can not take responsibility for the use of your scripts. It is up to you to use your discression and to create your scripts with the proper security features built-in to eliminate any possible misuses of your email form.
Can I have my visitors send email to others from my site?
It is not a good idea to allow your visitors to email others from your email forms. This opens your account to misuse which you will be held responsible for. Any domain that is found to be generating spam will be taken offline. It is best to hard-code the receiving email addresses into your script so that visitors can not send to just anybody. There are also other ways to ensure script security which are beyond the scope of this document.