Reputation: 53
I was playing around in Perl and I wrote a small email program. It went like this:
# -w
#the purpose of this program is to send an email .
print "Hello. Welcome to Paramjot's Mail Program. Please enter your name.\n";
$name = <STDIN>;
chomp ($name);
print "Hello, $name. Please type in the email address you wish to send your email to\n";
$mailadds = <STDIN>;
chomp ($mailadds);
open MAIL, "|mail $mailadds";
print "Please type the message you wish to send below.\n";
$message = <STDIN>;
chomp ($message);
print MAIL "$name says: $message";
close MAIL;
For some reason, when I run the program, it works until the program is supposed to ask for the message and instead says
mail is not recognized as a batch file, internal or external command, or an application.
What do I do to solve this problem?
Upvotes: 0
Views: 202
Reputation: 46207
The error message is coming from your operating system, not from Perl.
Your open
statement attempts to start up a new process running the command mail $mailadds
, but this fails because the operating system doesn't recognize the command mail
. To resolve the immediate error, you need to verify that mail
(or an equivalent program) is installed on your computer and change the open
statement to provide the full path and correct filename to that program.
The better solution to the overall task is to get a mail-handling module from CPAN and use that instead of calling an external program. Such modules provide a friendlier interface, plus they often abstract away any operating-system-specific details, like determining the correct name and location of the program used to send mail.
Personally, I tend to use MIME::Lite for this, although the module's maintainer advises against using it. The linked documentation includes suggestions of mail-sending modules that he considers to be "better alternatives" if you choose to heed his advice and not use MIME::Lite.
Upvotes: 1