电子邮件程序不能在Perl中工作
我在玩Perl,我写了一个小的电子邮件程序。事情是这样的:电子邮件程序不能在Perl中工作,perl,Perl,我在玩Perl,我写了一个小的电子邮件程序。事情是这样的: # -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 ad
# -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;
如何解决此问题?错误消息来自您的操作系统,而不是Perl
您的
open
语句试图启动运行命令mail$mailadds
的新进程,但这失败了,因为操作系统无法识别命令mail
。要解决即时错误,您需要验证计算机上是否安装了mail
(或等效程序),并更改open
语句以提供该程序的完整路径和正确文件名
对于整个任务,更好的解决方案是从CPAN获取邮件处理模块,并使用该模块,而不是调用外部程序。这样的模块提供了更友好的界面,而且它们通常会抽象掉任何操作系统特定的细节,比如确定用于发送邮件的程序的正确名称和位置
就个人而言,我倾向于使用它,尽管模块的维护人员建议不要使用它。链接文档包括邮件发送模块的建议,如果您选择听从他的建议而不使用MIME::Lite,他认为这些模块是“更好的选择”。您的
open
语句是我希望在*nix框中看到的那种,但错误消息闻起来像MS Windows。您确定要避免使用任何Mail/SMTP模块吗?我如何用windows更友好的语句替换open语句?请尝试MIME::Lite
、Net::SMTP
或类似操作
mail is not recognized as a batch file, internal or external command, or an application.