abully has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending HTML-formatted mail to a list
by thpfft (Chaplain) on Dec 16, 2001 at 10:23 UTC | |
|
Re: Sending HTML-formatted mail to a list
by Beatnik (Parson) on Dec 16, 2001 at 16:56 UTC | |
|
Re: Sending HTML-formatted mail to a list
by Chady (Priest) on Dec 16, 2001 at 20:39 UTC | |
by abully (Novice) on Dec 16, 2001 at 21:04 UTC | |
by dvergin (Monsignor) on Dec 17, 2001 at 04:03 UTC | |
by abully (Novice) on Dec 17, 2001 at 11:45 UTC | |
by Chady (Priest) on Dec 16, 2001 at 23:20 UTC | |
|
Re: Sending HTML-formatted mail to a list
by belg4mit (Prior) on Dec 16, 2001 at 23:00 UTC | |
|
Re: Sending HTML-formatted mail to a list
by trs80 (Priest) on Jan 20, 2002 at 06:56 UTC |