#!C:/Perl/bin/perl -w use strict; use CGI ':standard'; my $MAX = 10; # maximum in list my %list = (); my $confirm = param('confirm'); my $Email_List = param('Email_List'); # extract email adressess between () while ( $Email_List =~ m/\(([^)]+)/g ){ my $addr = $1; # remove spaces and any other cleaning here # assuming you don't have unusual addresses like # "Any Person"@somewhere.com $addr =~ s/ //g; # check valadity if ( is_valid($addr) ){ $list{$addr} = 'Not sent'; # using key avoids duplicates } } # check not too many my $msg; my $no = scalar(keys %list); if ($no > $MAX){ $msg = "ERROR - $no is too many to send"; } else { # send emails if confirm checked if ($confirm){ for (keys %list){ $list{$_} = send_to($_); # store result } } } # input form print header(), start_html; print qq!
##
# present result in a table
print '';
my $n = 0;
for (sort keys %list){
++$n;
print qq!
$n
$_
$list{$_}
!;
}
print '
';
print scalar localtime;
print end_html;
# your email routine here
sub send_to {
my $to = shift;
my $result = "Log or error for $to";
# $mail{To} = $to;
# if ( sendmail(%mail) ){
# $result = $Mail::Sendmail::log;
# } else {
# $result = $Mail::Sendmail::error;
# }
return $result; # either log or error msg
}
# check address is valid
sub is_valid {
my $addr = shift;
# make checks here as
# complicated as required
if ($addr =~ /\@/){
return 1;
}
return 0;
}