Use the very excellent MIME::Entity module to create an HTML email message. The following bit of untested code will build a message with a 'multipart/mixed" content-type which will allow the mail client to decide if it wants to display HTML content or text content. Personally I never open HTML only email (it's almost guaranteed to be spam).

use MIME::Entity; my $msg = MIME::Entity->build( Type => 'multipart/mixed', From => 'me\@domain.com', To => $recipient, Cc => \@cc, Subject => 'the subject', Encoding => '8bit', ); $msg->attach(Data => $text_message, Type => 'text/plain', Encoding => '8bit', ); $msg->attach(Data => $html_message, Type => 'text/html', Encoding => '8bit', ); ### Send it: open MAIL, "| /usr/sbin/sendmail -t -oi -oem" or die "open: $!"; $msg->print(\*MAIL); close MAIL;

Also, if you are sending the same message to all recipients, why are you sending them out separately. Just send out one email to all of them at once. That is what the Cc header is for.

One more note on your last question. You are mixing up the foreach syntax ( foreach (@array) ) with the for syntax ( for (my $i-0; $i < $max; $i++) ). With the foreach example $_ will contain the element that is in the array, not the index of the element. The following achieve the same result:

my @data = ('one', 'two', 'three'); foreach (@data) { print "$_\n"; } for (my $i=0; $i < @data; $i++) { print "$data[$i]\n"; } __output__ one two three one two three

In reply to Re: Sending HTML email and a slightly related 500 error by cees
in thread Sending HTML email and a slightly related 500 error by Foncé

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.