##################################################################### # # # M A S S M A I L E R # # # # Last modified: 1 Jul 2005 # ##################################################################### ##################################################################### # # # This mod will allow you (as admin) to send a message to multiple # # users in your database. # # # # The mod requires that you have the "sendmail" program on your # # system. # # # # Note that some servers bog down if a huge number of messages are # # sent at one time. Also, if you have a very large number of # # messages, your browser may time out before it gets finished. If # # this happens, send your message in batches, with more # # restrictive search criteria for each batch. # ##################################################################### ##################################################################### # file: default.cfg # # # # somewhere in the authentication definitions # # add the following # ##################################################################### # Full path to sendmail on your system $mailprog = "|/usr/lib/sendmail -t -oeq"; # Your email address $admin_email = 'you@yourserver.com'; # Fieldname that contains the email address of the user $db_email_field = 'Email'; ############################################################################### #file: db.cgi # # sub main # # # # within the other "elsif" statements # # add the following # ############################################################################### elsif ($in{'mass_mail_form'}) { if ($per_admin) { &html_mass_mail_form; } else { &html_unauth; } } elsif ($in{'mass_mail'}) { if ($per_admin) { &mass_mail; } else { &html_unauth; } } ############################################################################### #file: db.cgi # # new subroutine # # sub mass_mail # ############################################################################### sub mass_mail { # -------------------------------------------------------- # my ($i,$message,@lines,$line,$count,%rec,$mail_count); unless ($admin_email) { $message = "Admin email has not been entered in the .cfg file
"; } unless ($admin_email =~ /.+\@.+\..+/) { $message = "Admin email address is not in the correct format.
"; } unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.
"; } unless ($in{'emailmessage'}) { $message .= "Your email message is empty.
"; } for ($i = 0; $i <= $#db_cols; $i++) { if ($db_email_field eq $db_cols[$i]) { $found = 1; last; } } if (!$found) { $message .= "email field not found
"; } open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!"); @lines = ; close DB; $in{'mh'} = $#lines + 1; my ($status, @hits) = &query("view"); unless ($status eq 'ok') { $message .= "$status
"; } if ($message) { chomp($message); &html_mass_mail_form($message); return; } my ($numhits) = ($#hits+1) / ($#db_cols+1); for (0 .. $numhits - 1) { %rec = &array_to_hash($_, @hits); if ($rec{$db_email_field} =~ /.+\@.+\..+/) { open (MAIL, "$mailprog") || &cgierr("unable to open mail program"); print MAIL "To: $rec{$db_email_field}\n"; print MAIL "From: $admin_email\n"; print MAIL "Subject: $in{'subject'}\n\n"; print MAIL "-" x 75 . "\n\n"; print MAIL $in{'emailmessage'}; close (MAIL); ++$mail_count; } } &html_mass_mail_success($mail_count); } ############################################################################### #file: html.pl # # sub html_footer # # # ############################################################################### print qq!| Send Mass Mail ! if ($per_admin); ############################################################################### #file: html.pl # # new subroutine # # sub html_mass_mail_form # ############################################################################### sub html_mass_mail_form { #---------------------------------------------------------- my ($message) = $_[0]; &html_print_headers; print qq| $html_title: Mass Mailer
$html_title: Mass Mailer

<$font_title> Mass Mailer

|; if ($message) { print qq|There was a problem: $message|; } print qq| <$font>Fill in the subject of your message, the message you wish to send and the criteria for the users to whom you wish to send the email. |; print qq|
<$font>Subject:
<$font>Your message:
|; &html_record_form(%in); print qq|
|; &html_footer; print qq|
|; } ############################################################################### #file: html.pl # # new subroutine # # sub html_mass_mail_success # ############################################################################### sub html_mass_mail_success { #----------------------------------------------- my ($message) = $_[0]; &html_print_headers; print qq| $html_title: Mass Mailing Successful
$html_title: Send an email

<$font_title> Mass Mailing Successful

|; print qq|<$font>Your email message was sent to $message users.|; &html_footer; print qq|
|; }