#!/usr/bin/perl -w # # Filename: mailto.cgi # Author: Anon # Date: 17/12/98 # Last Modified: 08/06/00 # Version: 2.1 # This script is used to send an email to someone with information gleaned from # a CGI form # # This script expects # a _to field (the mail address of the destination mailer) # a _subject field # any number of _cc and _bcc fields # # _success_url - the webpage to go to once the mail has been sent # _fail_url - the webpage to go to if the mail fails. # # _db_file - a tab deliminated file to write to (optional) # # Any other input parameters not beginning with an '_' are appended to # the mail message, this means you should call the submit buttons etc _submit, # or you'll get them appended to the mail message. # # Any input parameters that begin with '++' HAVE to be filled in or you get # redirected to the _fail_url # # -------------------------------------------------------------------------------------------- # # Copyright (c) 1998 - 2001 ComputerTorture # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # -------------------------------------------------------------------------------------------- use CGI; use CGI::Carp qw (fatalsToBrowser); use strict; require Mail::Send; my $db_file = '/tmp/dbfile.txt'; while(my $query = new CGI) { handle_request($query); exit(0); } sub handle_request { my $query = shift; my @param_list = $query->param; # Check the fields that must be filled in.... foreach my $name (@param_list) { if ($name =~ /^\+/ and $query->param(-name => $name) !~ /\S/) { print $query->redirect(-uri => $query->param(-name => '_fail_url')); return; } } # Get the cc and bcc fields: my @cc_list = $query->param(-name => '_cc'); my @bcc_list = $query->param(-name => '_bcc'); my $msg = new Mail::Send; $msg->to($query->param('_to')); $msg->subject($query->param('_subject')); foreach (@cc_list) { $msg->cc($_); } foreach (@bcc_list) { $msg->bcc($_); } my $fh = $msg->open; open DATAFILE, ">>" . $db_file or die "cannot open database file $db_file"; foreach my $name ($query->param) { next if $name =~ /^_/; my $value = $query->param(-name => $name); $name =~ s/^\+//; $value =~ s/^on/yes/; print $fh "\n$name:\n" . $value . "\n"; print DATAFILE "$value\t"; } print DATAFILE "\n"; close(DATAFILE) or warn "Could not close DB File"; $fh->close; print $query->redirect(-uri => $query->param(-name => '_success_url')); }