You said:

I have tried everything, including these things:
$__to =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__cc =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; ...

Um, 'scuse me, but in your OP code snippets, you had this:

my %mail = ( "To" => "$__to", "Subject" => "$__subject", "Content-Type" => $__content_type, );
And you didn't really show us where the values of those scalars are coming from. Which means that these hash elements might never have had any line termination characters of any kind (in which case your substitutions would do nothing at all), or if they did have CR and/or LF, you might be screwing things up by having any sort of line-termination characters at all in those header values (this seems more likely).

You might want to try this (if you haven't already):

for ( $__to, $__subject, $__content_type, ... ) { tr/\r\n/ /; s/\s+$//; } my %mail = ( "To" => $__to, "Subject" => $__subject, "Content-Type" => $__content_type, );
That will tell you whether Mail::Sendmail does the right thing in terms of appending CRLF at the end of every header field. If those strings already have CR and/or LF in them, you are probably asking for trouble. Ideally, Mail::Sendmail would be smart enough to make sure that any header field value does not contain either CR or LF before the module itself appends CRLF to each header field for output. (Having spurious CR and/or LF scattered around in the header fields is a Bad Thing.)

As for the message body, I'd be inclined to try something like this:

my @message_lines = ( '', # blank line 'This is a multi-part message in MIME format.', '','', # a couple blank lines "------=$_random_boundary", ..., # i.e. one array element for every line of message content '','' # including a couple blanks at the end ); my $_mail_message = join( "\r\n", @message_lines );

My apologies for giving bad advice earlier (adding "\r" to the header fields) -- I should have known better.


In reply to Re^3: problem with 'bare LF' in script by graff
in thread problem with 'bare LF' in script by powerhouse

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.