I'm building a form mailer consisting of two textfields and one textarea that will send out those ultra-fancy HTML-formatted emails.

The big idea is for my client to paste his code into the textarea and the script will read a flat file of email addresses, tuck them into an array and interate through the list. It's one .cgi file using CGI.pm and its syntax for the creation of the form. It works perfectly if I hard-code an address in the $to variable, but when I have read in a test file (consisting of 3 addresses), it only sends the message to the first recipient, but if I print the contents of the array, my 3 values are intact.

What's more, when I attempt to test the script using the array values, my email client shows the raw HTML, but if I use the single-address test, I get the page that looks all nifty.

The magic is housed in a subroutine, and I've been focusing on my code for populating the array and my foreach loop--I know this is staring me in the face, but I'm fairly new to Perl and I've had no success in crafting a solution together perusing the site and my now well-worn copy of the Llama book. (Although it's done wonders for my syntax!) Please help? My subroutine is as follows:

sub send_message { $dir = "/blast/"; $file = "${dir}/file.txt"; open MAILIST, "<$file" or die "Can't create filehandle: $!"; while(<MAILIST>) { push (@address, $_); } close MAILIST or die "Can't close filehandle:$!"; $mailprogram = '/usr/lib/sendmail'; open( MAIL,"|$mailprogram -t" ) or die "Can't open sendmail! ($!)"; foreach (@address) { $from = $q->param( 'mail_from' || '' ); $subject = $q->param( 'mail_subject' || '' ); $message = $q->param( 'html_message' || '' ); $headers = "Content-Type: text/html; charset=iso-8859-1\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Transfer-Encoding: 7bit\r\n"; print MAIL "To: $_\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n"; print MAIL '$headers'; print MAIL '$message'; } return close(MAIL); }

Thankyouthankyouthankyou!

"Do or do not--there is no try." --Yoda

In reply to Sending HTML-formatted mail to a list by abully

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.