Hi there,

I am having issues with the format of the emails sent via MIME::Lite.

I am outputting two items of data per line. The first column of data is not fixed length, and I want the second item of data to be correctly aligned in the same position each time so I am using sprintf to format the data.

The print command output illustrates that the data is been outputted correctly but when I receive my email the data is all over the place.

What I did notice in my eclipse Perl environment that the string is padded out exactly like it outputs in my email, yet the print statement shows the data correctly aligned!!!

Any help on why the formatting is all over the place would be appreciated. The mailer is doing its job correctly and working with the data given. The problem seems to be with how sprintf holds the data internally.
use MIME::Lite; $smtp = "mailserver"; $internal_email_address = 'myemailaddess'; $a = sprintf ("%-90s %-s\n", "the amount for Apple is ","34"); $b = sprintf ("%-90s %-s\n", "the amount for Lemons is", "7"); print $a; print $b; $c = $a.$b; mailer( $internal_email_address,"issue", $c); sub mailer { my ( $addr, $subj, $output ) = @_; print "$_\n" for $addr; print "$_\n" for $subj; print "$_\n" for $output; $msg = MIME::Lite->new( From => 'xxxx', To => $addr, Subject => $subj, Data => $output ); MIME::Lite->send( 'smtp', $smtp, Timeout => 60 ); eval { $msg->send }; $mailerror = "Status: ERROR email - MIME::Lite->send failed: $@\n" + if $@; if ( $mailerror eq '' ) { $status = "Status: Mail sent\n"; } else { $status = $mailerror; } }

In reply to sprintf format and print inconsistencies whilst creating fixed width column by newbieperlperson

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.