Okay. Here's what I came up with. It does not do any error-checking to make sure the email address is correct.
In default.cfg add
Code:
# Your email address. Be sure to leave in the \ before the @
$admin_email = "you\@server.com";
# Email program on your system -- leave the flags as they are so any errors will be caught
$mailprog = "|/usr/sbin/sendmail -t -oeq";
# Field number of email field
$db_email_field = 4;
Change the above values to match your system and your database.
In db.cgi, sub main, in the midst of all the other "elsif" statements, add
Code:
elsif ($in{'send_email_form'}) { if ($per_admin) { &html_send_email_form; }else { &html_unauth; } }
elsif ($in{'send_email'}) { if ($per_admin) { &send_email; } else { &html_unauth; } }
Somewhere in db.cgi, add the following new subroutine:
Code:
sub send_email {
#-----------------------------------
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
open (DB, "<$db_file_name") or &cgierr("error in send email. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { next LINE; }
chomp ($line);
@data = &split_decode($line);
push(@email_list,$data[$db_email_field]);
}
foreach $email (@email_list) {
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $email\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);
}
&html_send_email_success;
}
In html.pl add the following two subroutines:
Code:
sub html_send_email_form {
#--------------------------------
my ($message) = $_[0];
&html_print_headers;
# <-- top of page formatting -->
print qq|
<html><head><title>$html_title: Send an email</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Send an email</b></td></tr>
<tr><td><p><center><$font_title><b>Send an email</b></font></center><br>|;
# <-- introductory text -->
if ($message) { print qq|There was a problem: $message|; }
print qq|
<$font>Fill in your email address, the subject of your email and the
message you wish to send.</font>
|;
# <-- email form -->
print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<table>
<tr><td align=right><$font>Subject:</font></td>
<td><input type=text name="subject" value="$in{'subject'} size=40></td></tr>
<tr><td align=right><$font>Your message:</font></td>
<td><textarea name="emailmessage" width=40 height=10>$in{'emailmessage'}</textarea></td></tr>
</table>
<center>
<INPUT TYPE="SUBMIT" NAME="send_email" VALUE="Send Email">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center>
</form>
|;
# <-- end of page formatting -->
&html_footer;
print qq|</td></tr></table></body></html>|;
}
sub html_send_email_success {
#----------------------------------
&html_print_headers;
# <-- top of page formatting -->
print qq|
<html><head><title>$html_title: Send an email</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Send an email</b></td></tr>
<tr><td><p><center><$font_title><b>Email sent</b></font></center><br>
|;
# <-- text -->
print qq|<$font>Your email message was sent.</font>|;
# <-- end of page formatting -->
&html_footer;
print qq|</td></tr></table></body></html>|;
}
In html.pl, sub html_footer, add the following line:
Code:
print qq!| <A HREF="$db_script_link_url&send_email_form=1">Send mass mailing</A> ! if ($per_admin);
I have tested this for syntax errors, but that's all. Seems like it would work.
------------------
JPD