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

In reply to Re^3: Email To A List Of Addresses by poj
in thread Email To A List Of Addresses by Milti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.