why does this script not work?

M

Mark Tarver

Hi,

This is a perl program I cribbed for sending the mail from a series of
forms. It fails to work with the message.


Software error:
Can't open mailprog.


For help, please send mail to this site's webmaster, giving this error
message and the time and date of the error.


Any ideas why?


Mark
___________________________________________________________________________­__

#!/usr/bin/perl -wT
use CGI qw:)standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;


#me! and you! replace real addresses


open(SENDMAIL, "/usr/sbin/sendmail -oi -t -odq") or die "Can't fork for

sendmail: $!\n";
print SENDMAIL <<"EOF";
From: me!
To: you!
Subject: form
my $name = param('name');
my $email = param('email');
my $commqi = param('commqi');
my $commqitk = param('commqitk');
my $inform = param('inform');
my $support = param('support');
my $consultation = param('consultation');
my $lisp = param('lisp');
my $os = param('os');
my $remarks = param('remarks');
EOF
close(SENDMAIL) or warn "couldn't close sendmail";
 
M

Mark Tarver

Mirco said:
Thus spoke Mark Tarver (on 2006-12-02 23:47):

use a pipe ('|'):

my $mailer = "/usr/sbin/sendmail -oi -t -odq";
open(SENDMAIL, "|$mailer") or die "Can't fork for sendmail: $!\n";


You have a space ' ' after EOF


Regards

M.

Right; makes sense. Thanks; I now have this. xxxxxx, yyyyyy replace
real addresses.

#!/usr/bin/perl -wT
use CGI qw:)standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

#print header;
#print start_html("Results");

# Set the PATH environment variable to the same path
# where sendmail is located:

# $ENV{PATH} = "/usr/sbin";

my $mailer = "/usr/sbin/sendmail -oi -t -odq";
open(SENDMAIL, "|$mailer") or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
From: xxxxxx
To: yyyyyy
Subject: form
my $name = param('name');
my $email = param('email');
my $commqi = param('commqi');
my $commqitk = param('commqitk');
my $inform = param('inform');
my $support = param('support');
my $consultation = param('consultation');
my $lisp = param('lisp');
my $os = param('os');
my $remarks = param('remarks');
EOF

close(SENDMAIL) or warn "couldn't close sendmail";

But it still does not work - and with the same message.

Not certain of the significance of
You have a space ' ' after EOF

Mark
 
M

Mark Tarver

Yes; my mistake. Now thre is a new error

CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers.

which is an advance of sorts.

Mark
 
J

John W. Krahn

Mark said:
This is a perl program I cribbed for sending the mail from a series of
forms. It fails to work with the message.

Software error:
Can't open mailprog.

I don't see that message anywhere in your code below so it is probably some
other code that is giving you that message.

For help, please send mail to this site's webmaster, giving this error
message and the time and date of the error.

Any ideas why?

Perhaps if you showed the actual code that produced that message?

#!/usr/bin/perl -wT
use CGI qw:)standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

Because you have warnings and strict enabled this program *should* have
produced error messages along the lines of:

Global symbol "$name" requires explicit package name
Global symbol "$email" requires explicit package name
Global symbol "$commqi" requires explicit package name
Global symbol "$commqitk" requires explicit package name
Global symbol "$inform" requires explicit package name
Global symbol "$support" requires explicit package name
Global symbol "$consultation" requires explicit package name
Global symbol "$lisp" requires explicit package name
Global symbol "$os" requires explicit package name
Global symbol "$remarks" requires explicit package name

#me! and you! replace real addresses


open(SENDMAIL, "/usr/sbin/sendmail -oi -t -odq") or die "Can't fork for
sendmail: $!\n";

You are trying to open the literal file named '/usr/sbin/sendmail -oi -t -odq'
but it most likely does not exist. What you should be doing is piping your
output to the sendmail program:

open my $SENDMAIL, '|-', '/usr/sbin/sendmail', '-oi', '-t', '-odq'
or die "Can't fork for sendmail: $!\n";

print SENDMAIL <<"EOF";

The following lines up to the "EOF" label are the contents of a double quoted
string.

From: me!
To: you!
Subject: form
my $name = param('name');

Putting aside the error message because of the global symbol, the previous
single line would print out as:

"my = param('name');\n"

You probably want to look at this FAQ to do what you want:

perldoc -q "How do I expand function calls in a string"

Or define the variables outside the string first before you use them.

my $email = param('email');
my $commqi = param('commqi');
my $commqitk = param('commqitk');
my $inform = param('inform');
my $support = param('support');
my $consultation = param('consultation');
my $lisp = param('lisp');
my $os = param('os');
my $remarks = param('remarks');
EOF

Your here doc (<<"EOF") defines the end of the string as "\nEOF\n" but you are
using "\nEOF \n" so it will never match and will produce the error message:

"Can't find string terminator "EOF" anywhere before EOF"




John
 
T

Tad McClellan

print SENDMAIL <<"EOF";
From: xxxxxx
To: yyyyyy
Subject: form
my $name = param('name');
my $email = param('email');
my $commqi = param('commqi');
my $commqitk = param('commqitk');
my $inform = param('inform');
my $support = param('support');
my $consultation = param('consultation');
my $lisp = param('lisp');
my $os = param('os');
my $remarks = param('remarks');
EOF


All of that is a _string_, only the print() is code, the rest is data.

You cannot declare variables and call functions inside of a string.

I guess the param('name') part is supposed to be part of the _body_
of the message? If so, then you need a blank line before it to
mark the end of the headers.


Get your program working from the command line before trying
it in a CGI environment.
 
M

Mark Tarver

This was the original program.

#!/usr/bin/perl
#use strict;
use warnings;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $mailprog = "/usr/sbin/sendmail -oi -t -odq";

#EMAIL
open (MAIL, "|$mailprog") || die "Can't open mailprog.\n";
print MAIL "To: xxxx";
print MAIL "Reply-To: nobody\n";
print MAIL "From: computer\n";
print MAIL "Subject: Inquiry Response Request\n\n";
print MAIL "howdy";

close(MAIL);

produces

Can't open mailprog.

Mark
 
M

Mumia W. (reading news)

This was the original program.

#!/usr/bin/perl
#use strict;
use warnings;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $mailprog = "/usr/sbin/sendmail -oi -t -odq";

#EMAIL
open (MAIL, "|$mailprog") || die "Can't open mailprog.\n";

The variable $! will contain the error message from open(). Print it if
you die:

open (MAIL, "|$mailprog") || die "Can't open mailprog: $!\n";

print MAIL "To: xxxx";

There is no \n on the end of the string above.
print MAIL "Reply-To: nobody\n";
print MAIL "From: computer\n";
print MAIL "Subject: Inquiry Response Request\n\n";
print MAIL "howdy";

Again, there is no \n on the end of the string above. Sendmail probably
requires that.
 
J

Joe Smith

Mark said:
This was the original program.

print MAIL "Subject: Inquiry Response Request\n\n";
print MAIL "howdy";

Note carefully that the original program has "\n\n" at the end of the
headers. That is important. You must include that blank line before
the body of your message.

print SENDMAIL <<"EOF";
From: me!
To: you!
Subject: form

EOF
print SENDMAIL '$',"$_ = ", param($_), "\n" foreach qw(name email commqi
commqitk inform support consultation lisp os remarks)';
close SENDMAIL or warn "couldn't close sendmail: $! ($?)\n";

-Joe
 
M

Mark Tarver

The variable $! will contain the error message from open(). Print it if
you die:

open (MAIL, "|$mailprog") || die "Can't open mailprog: $!\n";

Righto. Now we get.

Software error:
Can't use an undefined value as filehandle reference at
e:\domains\l\lambdassociates.org\user\htdocs\cgi-bin\register.cgi line
9.

For help, please send mail to this site's webmaster, giving this error
message and the time and date of the error.

Line 9 in my version corresponds with

open (MAIL, "|$mailprog") || die "Can't open mailprog: $!\n";

Mark
 
A

A. Sinan Unur

Righto. Now we get.

Software error:
Can't use an undefined value as filehandle reference at
e:\domains\l\lambdassociates.org\user\htdocs\cgi-bin\register.cgi line
9.

Since you have a prior record of not posting the exact code you are
using, it would be great to see the exact code you used when you got
this error message.

Sinan
--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
M

Mark Tarver

The exact script now fails with

Can't open mailprog. Bad file descriptor

#!/usr/bin/perl
#use strict;
use warnings;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $mailprog = "/usr/sbin/sendmail -oi -t -odq";

#EMAIL
open (MAIL, "|$mailprog") || die "Can't open mailprog. $!\n";
print MAIL "To: xxx\n";
print MAIL "Reply-To: nobody\n";
print MAIL "From: computer\n";
print MAIL "Subject: Inquiry Response Request\n\n";
print MAIL "howdy\n";

close(MAIL);
 
A

A. Sinan Unur

[ *Please* do not top-post and do not quote sigs ]
The exact script now fails with

Can't open mailprog. Bad file descriptor

#!/usr/bin/perl
#use strict;

Don't comment out use strict.
use warnings;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $mailprog = "/usr/sbin/sendmail -oi -t -odq";

#EMAIL
open (MAIL, "|$mailprog") || die "Can't open mailprog. $!\n";

What happens when you try to run /usr/sbin/sendmail from the command
line?

What does

$ which sendmail

tell you?

Sinan
 
M

Mumia W. (reading news)

The exact script now fails with

Can't open mailprog. Bad file descriptor

#!/usr/bin/perl
#use strict;

Don't disable strictures.
use warnings;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $mailprog = "/usr/sbin/sendmail -oi -t -odq";

#EMAIL
open (MAIL, "|$mailprog") || die "Can't open mailprog. $!\n";
print MAIL "To: xxx\n";
print MAIL "Reply-To: nobody\n";
print MAIL "From: computer\n";
print MAIL "Subject: Inquiry Response Request\n\n";
print MAIL "howdy\n";

close(MAIL);

Be sure to post your replies below the other person's text if you don't
want to get killfiled.

IOW, don't top-post. Read and follow the posting guidelines for this
newsgroup: http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

Turn "MAIL" into a lexical file handle, e.g.
my $MAIL;
open ($MAIL, ...

Also try putting the contents of $mailprog directly into the open
statement. If none of that works, you're on your own.

Good luck.
 
D

Dave Weaver

Yes; my mistake. Now thre is a new error

CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers.

That's becuase your script looks like this (taken from your previous
post):

#!/usr/bin/perl -wT
use CGI qw:)standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

#print header;
#print start_html("Results");
^
|
These lines are commented out so your script is not outputting the CGI
headers, hence the error.
 
M

Mark Tarver

It seems that my server does not support sendmail since it is a Windows
machine - contrary to the info on sendmail put on their site.

Thanks for all your help. I'm moving the account to Linux.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top