The code below works (when used with real addresses etc.). It sends a weekly email newsletter out via a very simple HTML form. Right now I simply paste the email mailing list into the script. Eventually, it will talk to a MySQL database.

Honestly, I wasn't really expecting this to get very large. I greatly underestimated the popularity of my client. She is getting about 100 people signing up for her newsletter every week.

I am worried that this code is simply not robust enough for a large mailing list. For example, could it time out before delivering all the messages if the email list got too long?

Please let me know how I can improve this script as: (a) the mailing list grows, (b) I intergrate it with MySQL, and (c) I eventually turn the mailing of the newsletter over to office staff.

#!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; my $request = new CGI; my @emaillist = ("name\@domain.com","anothername\@anotherdomain.com"); my $messagebody = ""; my @form_fields = $request -> param; my $thankyoupage = 'http://www.domain.com/Thanks.html'; my $field = ""; foreach $field (@form_fields) { my $value = $request -> param ($field); my $f = uc ($field); $messagebody .= $value . "\n\n"; } my $n = ""; foreach $n (@emaillist) { open(MAIL, "|/usr/sbin/sendmail -t") or die "Could not open Sendmail \ +n\n $!"; print MAIL "To: $n\n"; print MAIL "From: newsletter\@domain.com\n"; print MAIL "Subject: The Weekly Newsletter\n"; print MAIL "Content-type: text/plain\n\n"; print MAIL "$messagebody\n\n"; close(MAIL) or die "Could not close Sendmail \n\n $!"; } print "Location: $thankyoupage\n\n"; exit;

In reply to Send mail with large address book by Valkerri

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.