Gurpreet Singh wrote:
Hi All,
Hello,
I am a beginner of perl and sorry if I am asking something silly. I have written the following code using some pre-made scripts on net. #!/usr/bin/perl
You should have these two lines next: use warnings; use strict;
l1:print"Enter your E-Mail ID";
Why the label? Are you using goto's somewhere?
my $from=<STDIN>;
When you accept input from STDIN it is terminated by a newline so you probably want to use chomp() to remove it.
l2:print"Enter receipt's E-Mail ID";
Again, why the label?
my $to=<STDIN>; print"Enter Subject"; my $sub=<STDIN>; print"Enter Body"; my $body=<STDIN>; open (MAIL,"|/usr/sbin/sendmail");
You should verify that the pipe opened correctly: open MAIL, '|-', '/usr/sbin/sendmail' or die "Cannot open pipe to sendmail: $!";
print MAIL "To: $to\n";
Because of the newline remaining in $to you effectively have two newlines at the end.
print MAIL "From: $from\n"; print MAIL "Subject: $sub\n\n"; print MAIL "$body\n";
Strictly speaking, most internet protocols terminate lines with the CRLF pair of characters.
close MAIL;
You should verify that the pipe closed correctly: close MAIL or warn $! ? "Error closing sendmail pipe: $!" : "Exit status $? from sendmail"; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall Thu Jan 3 10:11:26 UTC 2008 M -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/