I'm assuming that, since you are using a form, the data is coming in from an application/x-www-form-urlencoded POST. You have the option of passing the data either as a single field value that you'll pull in as a scalar:
my $email_list = param ('Email_List');
or you can have a large number of inputs (one for each address) and use array access to the parameters:
my @email_list = param ('Email');
Note that this capability to have repeat keys in HTTP requests has caused a large number of issues over the years, because people can completely miss entries if they call param in scalar context. This means it might be a future gotcha. You'll also probably want some javascript on you page for 'Add additional recipient' in that scenario.

Your post sounds like you would prefer a big cut-paste blob into a textbox, and then process that list on the server. A split as Corion suggests would then be a natural processing approach, but could easily be frustrated depending on how you are formatting you list. If you want to include addresses of the format

Smith, Peter (PERL) <peter.smith@perl.com>
you couldn't use commas as separators, for example. Regardless, you could implement your loop with something like:
##sendmail_email.pl #!C:/Perl/bin/perl -w use CGI qw(:standard); use HTML::Entities; use Mail::Sendmail 0.79; # doesn't work with v. 0.74! my $Sender=param('Sender'); my $email_list=param('Email_List'); my $Subject=param('Subject') my $Message = encode_entities(param ('Message')); #SEE WHAT I DID HERE $html = <<END_HTML; <p>$Message</p><p><font size="2"> END_HTML for my $email (split /;/, $email_list) { my %mail; $mail{Smtp}="smtp.sendgrid.net"; $mail{Port}=587; $mail{Auth}={user=>"Milt1", password=>"XXXXXXX", method => "LOGIN" +, required => 1}; $mail{To}=$email; $mail{From}= $Sender; $mail{Subject}=$Subject; $mail{'content-type'} = 'text/html; charset="iso-8859-1"'; $mail{body} = <<END_OF_BODY; <html>$html</html> END_OF_BODY sendmail(%mail) || print "Error: $Mail::Sendmail::error\n"; } &redirect; sub redirect { print header(), start_html; print "Your Message Was Sent\n\n"; } exit;

Finally, as a side note, depending on how visible this service is, you have some mighty security holes present there. At the least, someone can use this as a SPAM generator, and will be able to do so even more once they could submit 1000 email addresses in a go. There are also like some injection attack sensitivities, since you have not done any input filtering and are just interpolating.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


In reply to Re: Email To A List Of Addresses by kennethk
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.