I've got a simple routine to fire out emails. I noticed with some calls the mails appeared as expected, but with others the linefeeds were not working. Instead of appearing on a new line there'd just be a space and then the text.
When this happens in Outlook you can enable/disable "Wrap" and the message will appear correctly/incorrectly.
There's something here I don't understand, and hope someone can point out what's going wrong.
The following example sends out two emails, one with double linefeeds and one with single linefeeds. The one with double linefeeds behaves as expected. The one with single line feeds does not!
#!/usr/bin/perl
# Choice method of sending, sendmail or SMTP
$mail_prog='smtp:mail.MYWEBSITE.com';
#$mail_prog="/usr/sbin/sendmail";
$addr_to="neil\@MYEMAIL.com";
$addr_from="hi\@MYEMAIL.com";
$|=1;
print "Content-type:text/html;charset=ISO-8859-1\n\n<pre>";
print "Mail Test program...\n";
# Get a blank line between each line (as expected)
$rest_of_msg="Subject:This is a subject\n\n";
$rest_of_msg.="A reply has been posted to your message on the website
+blah blah blah.\n\n";
$rest_of_msg.="The URL for the response is\n\n";
$rest_of_msg.="http://www.awebsite.com/cgi/software/program.pl?f=1&m=2
+54388&df=1\n\n";
&send_an_email($addr_to,$addr_from,$rest_of_msg);
# Doesn't do any line feeds!
$rest_of_msg="Subject:This is a subject\n\n";
$rest_of_msg.="A reply has been posted to your message on the website
+blah blah blah.\n";
$rest_of_msg.="The URL for the response is\n";
$rest_of_msg.="http://www.awebsite.com/cgi/software/program.pl?f=1&m=2
+54388&df=1\n";
&send_an_email($addr_to,$addr_from,$rest_of_msg);
print "Sent!";
exit;
sub send_an_email{
my($to,$from,$rest)=@_;
if(substr($mail_prog,0,5) eq 'smtp:'){
require Net::SMTP;
my $smtp=substr($mail_prog,5);
$smtp = Net::SMTP->new($smtp);
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To:$to\nFrom:$from\n$rest");
$smtp->dataend();
$smtp->quit();
}else{
open MAIL,"|$mail_prog -t";
print MAIL "To:$to\nFrom:$from\n$rest";
close MAIL;
}
}
The two emails I get appear line this:-
A reply has been posted to your message on the website blah blah blah.
The URL for the response is
http://www.awebsite.com/cgi/software/program.pl?f=1&m=254388&df=1
A reply has been posted to your message on the website blah blah blah. The URL for the response is http://www.awebsite.com/cgi/software/program.pl?f=1&m=254388&df=1
Like I say some emails I send appear absolutely fine so I'm not sure if length of lines play some part in it working? But something very odd is going on!?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.