in reply to Sending HTML-formatted mail to a list

This looks rather strange:

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);

I think you meant :

foreach (@address) { open MAIL,"|$mailprogram -t" or die "Can't open sendmail! ($!)"; $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'; close MAIL; }

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re: Re: Sending HTML-formatted mail to a list
by abully (Novice) on Dec 16, 2001 at 21:04 UTC

    I initally had this in my code, but changed it after thinking that instead of opening the MAIL filehandle on every interation of the loop, I'd open MAIL once, loop thru all the addresses, then close the filehandle. Is that wrong?

    "Do or do not--there is no try." --Yoda
      Chady underestimates his grasp of the problem. Yes, the second and third emails are getting lost in some sort of HTML-mail muddle as useless additions to the body of the first email. You must close and re-open the sendmail pipe to send subsequent emails.

      Or include all three addresses on the "To:" line and send them all at once.

      ------------------------------------------------------------
      "Perl is a mess and that's good because the
      problem space is also a mess.
      " - Larry Wall

        Thanks--you totally helped me. After cleaning up the syntax, I did a test to find a single element in the array:
        foreach $address (@address) { print "$address\n"; }
        From this, I found that $address is all of my addresses in the test file (three entrys). So it thinks that all three addresses correspond to one array element!

      I'm not really sure, but I think that you need to close sendmail so it can send the email, or else, it will keep on printing the text in the body of the current email, and that's why you're getting only the first email sent.. because the rest of the emails are just body in the first one.

      then again, I might be wrong.


      He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

      Chady | http://chady.net/