Lets tidy that up a bit, shall we?
- Enable strict, and warnings (always a good idea - and if you'd enabled them in the first place you would have realised that you do not assign a value to $from),
- Allow the user to enter multi-line messages,
- Apply a bit of consistency (ie. you use <> on one line, and <STDIN> on another),
- Simplify a few of the statements,
- Apply some sensible code indenting and a bit of whitespace, for readability.
And this gives us:
#!/usr/bin/perl
use strict;
use warnings;
use Mail::Mailer;
my $mailer = Mail::Mailer->new("sendmail");
print "\nRecipient Address:";
chomp (my @to = split /;/,<STDIN>);
print "\nFrom:";
chomp (my $from = <STDIN>);
print "\nSubject:";
chomp(my $subject = <STDIN>);
print "\nContent (END to end):";
my $content;
while (1) {
my $line = <STDIN>;
last if $line eq "END\n";
$content .= $line;
}
$mailer->open( {
From => $from,
To => \@to,
Subject => $subject
});
print $mailer $content;
close($mailer);
Of course, one other thing you should consider is some data validation, but that's left as an exercise for the reader :)
Cheers,
Darren :)
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.