views:

270

answers:

3

Here's my code that is not working:

print "To: ";  my $to=<>;  chomp $to;
print "From: ";  my $from=<>;  chomp $from;
print "Attach: "; my $attach=<>; chomp $attach;
print "Subject: "; my $subject=<>; chomp $subject;
print "Message: "; my $message=<>; chomp $message;

my $mail_fh = \*MAIL;
open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";
print $mail_fh $message;
close($mail_fh);

The mailx command works fine off the command line, but not in this Perl script context.

Any idea what I'm missing?


I suspect that this line's format/syntax:

open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";

is the culprit.

+2  A: 

Do you really want to use external binaries for either the uuencode or the mailx bit? UUencode is almost trivial with pack.

brian d foy
Quite trivial - `my $encoded = pack 'u', $data;` The `u` template is a bit weird, and isn't explained well in perlfunc. There is an example in perlpacktut though: http://perldoc.perl.org/perlpacktut.html#Uuencoding
daotoad
+2  A: 

You just need an extra | at the beginning:

open $mail_fh, "|uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to"; 
Gabe
+1  A: 

There are other ways to send mail. See the How do I send mail? in perlfaq9.

ghostdog74