###############################################################################
# #
# P R I V A T E M A I L E R #
# #
# Last modified: 14 Mar 2006 #
###############################################################################
###############################################################################
# #
# 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 #
# and a field (checkbox or radio) where the user can opt in or opt out of #
# receiving emails through the database. The value for the field should be #
# "Yes" for those who wish to opt in. #
# #
###############################################################################
###############################################################################
# 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';
# Fieldname that contains the permission for emails to be sent
$db_opt_in_field = "Receive emails";
###############################################################################
#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 #
# sub get_record #
# #
# DELETE the following #
###############################################################################
($restricted = 1) if ($auth_modify_own and !$per_admin);
###############################################################################
#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'} =~ /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) { $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_record($in{$db_key});
if (!%rec) { $message .= "The email address you requested could not be found.
"; }
elsif (!$rec{$db_email_field}) { $message .= "There is no email address on file for this person.
" }
unless ($rec{$db_opt_in_field} eq 'Yes') { $message .= "This person has requested not to receive messages.
" } # Change this value to reflect the possible responses in your database
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $in{'email'}\n";
print MAIL "Subject: Message from $html_title\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "$in{'subject'}\n";
print MAIL "$in{'emailmessage'}";
close (MAIL);
&html_send_email_success;
}
###############################################################################
#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_record($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 $rec{'Name'}. |; print qq| |; &html_footer; print qq| | |
| $html_title: Send an email | |
|; print qq|<$font>Your email message was sent.|; print qq| | |