Hi Monks!
I have a Perl Module that sends email no problem, I am trying to this current module add the ability to send HMTL email, can anyone show me how I could add this feature to this module?
I added a line there but need to see if this is the best way to the current code I already have.
Thanks a lot!!!

sub my_sendmail { my ($to, $subject, $msg_body, $from_addr, $from_name, $to_name) = @_ +; my $input; # Make sure variables are set up correctly (ref($to) eq "ARRAY") || die "Argument \$to must be a reference to a +n array"; $subject = "(No subject)" unless ($subject); # Add the first email address to the To: name $to_name = ($to_name ? "$to_name " : ''); $to_name .= "<$to->[0]>"; # Use default 'from' address if not defined unless ($from_addr) { $from_addr = $default_from_addr; $from_name = $default_from_name; } # Add 'from' address to name. Some ISP's require a valid email in ' +From:' $from_name .= " <$from_addr>"; warn "<pre>\n" if ($sendmail_debug); warn "Calling SMTP server.\n" if ($sendmail_debug); my $sock = IO::Socket::INET->new( PeerAddr => $mail_server, Type => SOCK_STREAM, PeerPort => 'smtp(25)', Proto => 'tcp'); unless ($sock) { warn "Can't open a port on the mail server ($mail_server)."; return 0; } $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); print $sock "HELO localhost\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); print $sock "mail from:<$from_addr>\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); # Send to each recipient here. They won't see the others' addresses my $rcpt; foreach $rcpt (@$to) { print $sock "rcpt to:<$rcpt>\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); } print $sock "DATA\r\n"; print $sock "Subject: $subject\r\n"; print $sock "From: $from_name\r\n"; print $sock "Reply-To: $from_addr\r\n"; print $sock "To: $to_name\r\n"; print $sock "\r\n"; #test line to add HTML to the emails print $sock "Content-type: text/plain\n\n"; print $sock "$msg_body\r\n"; print $sock ".\r\n"; $input = <$sock>; warn "$input\r\n" if ($sendmail_debug); print $sock "QUIT"; close ($sock); return 1; } # End of my_sendmail() 1; # End of My Sendmail.pm __END__

In reply to Sending HTML emails HELP! by Anonymous Monk

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.