###############################################################################
# #
# P R I V A T E M A I L E R #
# #
# Last modified: 20 Apr 2000 #
# Modified 7 Mar 2004 for DBMan SQL version 1 by shann123 #
###############################################################################
###############################################################################
# #
# This mod will allow your users to receive email from other visitors to your #
# site, while at the same time maintaining some degree of privacy. Instead of #
# using a "mailto:" link with their email address, this mod creates a form #
# for the email and then looks up the recipient's email address in the #
# and sends it. #
# #
# The mod requires that you have the "sendmail" program on your system and #
# that you have a field in your database for the email address of each user. #
# #
###############################################################################
###############################################################################
# file: default.cfg #
# #
# somewhere in the authentication definitions #
# add the following #
###############################################################################
# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t -oeq";
# 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{'send_email_form'}) { &html_send_email_form; }
elsif ($in{'send_email'}) { &send_email; }
###############################################################################
#file: db.cgi #
# new subroutine #
# sub send_email #
###############################################################################
sub send_email {
# --------------------------------------------------------
# This subroutine added for the private email mod
#
unless ($in{'email'}) { $message = "You must fill in your email address
"; }
unless ($in{'email'} =~ /.+\@.+\..+/) { $message = "Your 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.
"; }
%rec = &get_user_data($in{$db_key});
if (!%rec) { $message .= "The email address you requested could not be found.
"; }
elsif (!$rec{$email}) { $message .= "There is no email address on file for this person.
" }
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $email\n";
print MAIL "From: $in{'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;
}
###############################################################################
#file: db.cgi #
# new subroutine #
# sub get_user_email #
# Change the numbers in "$email = $data[50]" & $name = $data[2] to match the #
# email and Name fields in your "Items" table. #
###############################################################################
sub get_user_data {
# --------------------------------------------------------
# Pulls the email address from the password file.
my $key = $_[0];
my ($sth, $query, @result, %result, $i, $key_q);
# If we are not passed in a key, return undef.
unless ($key) { return undef; }
$db_is_int{$db_key} ?
($key_q = int($key)) :
($key_q = $DBH->quote($key));
local $" = ',';
$query = qq!
SELECT @db_cols FROM $db_table
WHERE $db_key = $key_q
!;
my $sth = $DBH->prepare($query);
$sth->execute();
if ($sth->rows) {
while (@data = $sth->fetchrow_array) {
$email = $data[50];
$name = $data[2];
}
}
$sth->finish;
return $email;
}
###############################################################################
#file: html.pl #
# sub html_record #
# #
# Just after #
# my (%rec) = @_; #
# #
# Add #
###############################################################################
$rec{$db_key} =~ s/.B>//g;
###############################################################################
#file: html.pl #
# sub html_record #
# #
# Add this link somewhere in the subroutine, probably close to the end. #
###############################################################################
Send email to this person
###############################################################################
#file: html.pl #
# new subroutine #
# sub html_send_email_form #
###############################################################################
sub html_send_email_form {
#----------------------------------------------------------
my ($message) = $_[0];
$in{$db_key} =~ s/.B>//g;
%rec = &get_user_data($in{$db_key});
&html_print_headers;
print qq|
| $html_title: Send an email | |
|
|; 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 to $name. |; print qq| |; &html_footer; print qq| | |
| $html_title: Send an email | |
|; print qq|<$font>Your email message was sent.|; print qq| | |