This is a tweaked version of Dave Cross's FormMail.pl script, as well as doing all of it's FormMail goodness, it can also subscribe an email to a Dada Mail list. Instructions to install this script are below and you should follow them. You should first install Dada Mail and have the running correctly, before tackling this script.
In your html form, you need to also do a few things to clue Dada Mail what mailing list you want to work with:
example:
<input type='hidden' name='list' value='justin'>
example:
<input type='text' name='email'>
<input type="checkbox" name="add_email" value="1" /> Yes! Add my email to your list!
If you don't want to give your visitor a choice, just make this a hidden field:
<input type="hidden" name="add_email" value="1" />
Because this script has been tweaked to use the Dada Mail libraries, you may need to tell the script where those libraries are. If you install FormMail in your cgi-bin directory, a directory immediately below you cgi-bin directory or in the cgi-bin/dada directory, you should be alright. If not, you need to change the use lib ... line at the top of this script. The easiest thing to do is give an absolute path to both the dada and DADA directories:
use lib qw( /home/account/cgi-bin/dada /home/account/cgi-bin/dada/DADA );
lastly, the '-T' flag has been removed from this script, as the Dada Mail libraries probably won't run correctly with them on.
back to your regularly scheduled documentation...
# No __END__ here because that breaks under Apache::Registry
FormMail $Revision: 1.1.1.1 $ Copyright 2001 London Perl Mongers, All rights reserved
This script is free software; you are free to redistribute it and/or modify it under the same terms as Perl itself.
The most up to date version of this script is available from the nms script archive at <http://nms-cgi.sourceforge.net/>
formmail is a script which allows you to receive the results of an HTML form submission via an email message.
In this distribution, you will find the following files:
There are a number of variables that you can change in FormMail.pl which alter the way that the program works.
A $mailprog setting that works for many UNIX-like hosts is:
$mailprog = '/usr/lib/sendmail -oi -t';
Some other UNIX-like hosts need:
$mailprog = '/usr/sbin/sendmail -oi -t';
For hosts that lack a suitable sendmail binary (such as most Windows systems) we have a Perl script which does the job of the sendmail binary, in the nms_sendmail package at <http://nms-cgi.sourceforge.net/>. See the README file in the nms_sendmail package for instructions.
Example: to allow mail to be sent to 'you@your.domain' or any address at the host 'mail.your.domain', you would set:
@allow_mail_to = qw(you@your.domain mail.your.domain);
There is an implicit $ at the end of the regular expression, but you need to include the ^ if you want it anchored at the start. Note also that since '.' is a regular expression metacharacter, you'll need to escape it before using it in domain names.
If that last paragraph makes no sense to you then please don't put anything in @recipients, stick to using the less error prone @allow_mail_to.
For example, suppose you have three forms on your site,
and you want each to submit to a different email address
and you want to keep the addresses hidden. You might
set up %recipient_alias
like this:
%recipient_alias = ( '1' => 'one@your.domain', '2' => 'two@your.domain', '3' => 'three@your.domain', );
In the HTML form that should submit to the recipient 'two@your.domain', you would then set the recipient with:
<input type="hidden" name="recipient" value="2" />
Catalan ca_ES Croatian hr_HR Czech cs_CZ Danish da_DK Dutc nl_NL Estonian et_EE Finnish fi_FI French fr_FR Galician gl_ES German de_DE Greek el_GR Hebrew he_IL Hungarian hu_HU Icelandic is_IS Italian it_IT Japanese ja_JP Korean ko_KR Lithuanian lt_LT Norwegian no_NO Polish pl_PL Portuguese pt_PT Romanian ro_RO Russian ru_RU Slovak sk_SK Slovenian sl_SI Spanish es_ES Swedish sv_SE Thai th_TH Turkish tr_TR
%Y - four digit year (2002) %y - two digit year (02) %m - month of the year (01 to 12) %b - short month name (Jan to Dec) %B - long month name (January to December) %d - day of the month (01 to 31) %a - short day name (Sun to Sat) %A - long day name (Sunday to Saturday) %H - hour in 24 hour clock (00 to 23) %I - hour in 12 hour clock (01 to 12) %p - AM or PM %M - minutes (00 to 59) %S - seconds (00 to 59) %Z - the name of the local timezone
CAUTION: with this feature turned on it's possible for someone to put someone else's email address in the form and submit it 5000 times, causing this script to send a flood of email to a third party. This third party is likely to blame you for the email flood attack.
$confirmation_text = <<'END_OF_CONFIRMATION';
and
END_OF_CONFIRMATION
is treated as part of the email. Everything before the first blank line is taken as part of the email header, and everything after the first blank line is the body of the email.
$confirmation_text = <<'END_OF_CONFIRMATION'; From: you@your.com Subject: form submission
Thankyou for your form submission.
END_OF_CONFIRMATION
Formmail is installed simply by copying the file FormMail.pl into your cgi-bin directory. If you don't know where your cgi-bin directory is, then please ask your system administrator.
You may need to rename FormMail.pl to FormMail.cgi. Again, your system administrator will know if this is the case.
You will probably need to turn on execute permissions to the file. You can do this by running the command ``chmod +x FormMail.pl'' from your command line. If you don't have command line access to your web server then there will probably be an equivalent function in your file transfer program.
To make use of it, you need to write an HTML form that refers to the FormMail script. Here's an example which will send mail to the address 'feedback@your.domain' when someone submits the form:
<form method="post" action="http://your.domain/cgi-bin/FormMail.pl"> <input type="hidden" name="recipient" value="feedback@your.domain" /> <input type="text" name="feedback" /><br /> Please enter your comments<br /> <input type="submit" /> </form>
See how the hidden 'recipient' input in the example above told formmail who to send the mail to? This is how almost all of formmail's configuration works. Here's the full list of things you can set with hidden form inputs:
<input type="hidden" name="recipient" value="you@your.domain,me@your.domain" />
If you leave the 'recipient' field out of the form, formmail will send to the first address listed in the @allow_mail_to configuration variable (see above). This allows you to avoid putting your email address in the form, which might be desirable if you're concerned about address harvesters collecting it and sending you SPAM. This feature is disabled if the emulate_matts_code configuration variable is set to 0.
<input type="hidden" name="subject" value="From the feedback form" />
<input type="hidden" name="redirect" value="http://www.your.domain/foo.html" />
If you don't specify a redirect URL then instead of redirecting formmail will generate a success page telling the user that their submission was successful.
<input type="hidden" name="return_link_url" value="/home.html" />
<input type="hidden" name="return_link_title" value="Back to my home page" />
<input type="hidden" name="sort" value="order:name,email,age,comments">
For example:
<input type="hidden" name="print_config" value="title,sort">
... will include whatever values you set for title' and 'sort' (if any) in the email.
<input type="hidden" name="required" value="name,comments">
As well as all these hidden inputs, there are a couple of non-hidden inputs which get special treatment:
@referers = qw(dave.org.uk 209.207.222.64 localhost);
This use of the qw()
operator is one way to write lists of
strings in Perl. Another way is like this:
@referers = ('dave.org.uk','209.207.222.64','localhost');
We prefer the first version because it allows use to leave out
the quote character, but the second version is perfectly valid
and works exactly the same as the qw()
version. You should
use whichever version you feel most comfortable with. Neither
is better or worse than the other.
What you must not do is try to mix the two, and end up with something like:
@referers = qw('dave.org.uk','209.207.222.64','localhost');
This will not work, and you will see unexpected behavior. In
the case of @referers
, the script will always display a
``bad referer'' error page.
$mailprog = '/usr/lib/sendmail -oi -t';
This is actually two different pieces of information; the
location of the sendmail binary (/usr/lib/sendmail) and
the command line switches that must be passed to it in order
for it to read the list of message recipients from the
message header (-oi -t
).
If your hosting provider or system administrator tells you that
sendmail is /usr/sbin/sendmail on your system, then you must
change the $mailprog
line to:
$mailprog = '/usr/sbin/sendmail -oi -t';
and not:
$mailprog = '/usr/sbin/sendmail';
For support of this script please email: