If all the email addresses are enclosed in brackets then perhaps use a simple regex to extract them. Here is a basic test script to play around with. The added confirm checkbox lets you test before actually sending.
#!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!<h4>Recipients (maximum $MAX)</h4>
<form action="" method="post">
<textarea cols="80" rows="20" name="Email_List">
$Email_List
</textarea><br/>
<br/>
Confirm<input name="confirm" type="checkbox"/>
<input type="submit" name="action" value="Send"/>
</form><br/>
<span style="background-color:#ffff00">$msg</span>!;
# present result in a table
print '<table border="1" cellspacing="0" cellpadding="5">';
my $n = 0;
for (sort keys %list){
++$n;
print qq!<tr>
<td>$n</td>
<td>$_</td>
<td>$list{$_}</td>
</tr>!;
}
print '</table><br/>';
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;
}
poj