
BillKSmith
Veteran
Nov 2, 2012, 8:34 AM
Post #4 of 5
(3724 views)
|
Re: [sheet.pangasa] Stuck with email
[In reply to]
|
Can't Post
|
|
Your main problem is improper quoting. I can demonstrate what you re passing to the shell by printing your command.
sub func_sendmail { $input = 'my_mail.txt'; print qq(mail -s "$_[0]" "$_[1]" . "-- -f" . "$_[2]" < $input); # `mail -s "$_[0]" "$_[1]" . "-- -f" . "$_[2]" < $input`; } func_sendmail ( "subject", "to_address", "from_address" ); There are several other errors. Always use strict and warnings. Place subroutine definlition at end of program. Prototypes do not mean what you think. They should seldom be used. The function system (refer: perldoc -f system) is a better choice than backticks in this application. Combining these ideas:
use strict; use warnings; func_sendmail ( "subject", "to_address", "from_address" ); sub func_sendmail { my $input = 'my_mail.txt'; my $cmd = qq(mail -s $_[0] $_[1] -- -f $_[2] < $input); print $cmd, "\n"; my $status = system $cmd; print "Email status = $status\n"; } (untested - I do not have access to linix) Good Luck, Bill
|