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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |