I removed the second my and a few other small changes but nothing helped. The $signature shows up in the email if it exists and it prints to screen doing a db test print. If you run the script over again the $sig{$signature} doesn't stick and you get an empty string.
Any other suggestions?
#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX;
use CGI qw/:standard/;
require SDBM_File;
my %sig;
my $sigsave = "sig.dbm";
my %emails;
my $list = "list.dbm";
my $adminmail = "admin\@test.com";
my $sendmail = "/usr/lib/sendmail";
my $signature;
tie %emails, 'SDBM_File', $list, O_CREAT | O_RDWR, 0644;
if ( !tied %emails ) {
print "database unsuccessful $!.\n";
}
tie %sig, 'SDBM_File', $sigsave, O_CREAT | O_RDWR, 0644;
if ( !tied %sig ) {
print "database unsuccessful $!.\n";
}
print header, start_html('Email Management');
print "DB contents: $sig{$signature}\n";
print start_form(), table(
Tr(
td("Subject: "),
td(
textfield(
-name => 'subject',
-size => 40
)
)
),
Tr(
td("Message: "),
td(
textarea(
-name => 'message',
-columns => 40,
-rows => 5
)
)
),
Tr(
td("Signature: "),
td(
textarea(
-name => 'signature',
-default => $sig{$signature},
-columns => 40,
-rows => 5
)
)
),
Tr(
td(
checkbox_group(
-name => 'todo',
-values => [ 'use', 'save' ],
-rows => 2,
-columns => 2
),
),
td(submit)
),
),
end_form(), hr();
# rid ourselves from those nasty params
my $message = param('message');
my $subject = param('subject');
$signature = param('signature');
my $todo = param('todo');
if ( param() ) {
if ( $message && $subject eq "" ) {
print "Your subject or email content was missing.\n";
}
else {
foreach my $key ( keys %emails ) {
print "Things we have: $key <br>\n";
}
print "<br>\n";
while ( my ( $key, $value ) = each(%emails) ) {
# Email Subs, special commands
$message =~ s/\[name\]/$value/; #[name] = user name
open( MAIL, "| $sendmail -t" );
print MAIL "To: $key\n";
print MAIL "From: $adminmail\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n";
if ( $todo eq "use" && $signature ne "" ) {
print MAIL "$signature\n";
}
print MAIL ".\n";
close(MAIL);
print "Email was sent to: $key !<br>";
}
}
if ( $todo eq "save" ) {
print "<br>";
print "Saving to database<br>\n";
$sig{$signature} = $signature;
print "\$sig{\$signature}: $sig{$signature}";
}
}
untie %emails;
untie %sig;
|