Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 :)

Darren :)

In reply to Re: Email using sendmail by McDarren
in thread Email using sendmail by alandev

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 06:52 GMT
Find Nodes?
    Voting Booth?

    No recent polls found