Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > why does this script not work?

Reply
Thread Tools

why does this script not work?

 
 
Mark Tarver
Guest
Posts: n/a
 
      12-02-2006
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";

 
Reply With Quote
 
 
 
 
Mark Tarver
Guest
Posts: n/a
 
      12-02-2006
Mirco Wahab wrote:
> Thus spoke Mark Tarver (on 2006-12-02 23:47):
> > This is a perl program I cribbed for sending the mail from a series of
> > forms. It fails to work with the message.
> > ...
> > Any ideas why?
> >
> > open(SENDMAIL, "/usr/sbin/sendmail -oi -t -odq") or die "Can't fork for

>
> use a pipe ('|'):
>
> my $mailer = "/usr/sbin/sendmail -oi -t -odq";
> open(SENDMAIL, "|$mailer") or die "Can't fork for sendmail: $!\n";
>
> > print SENDMAIL <<"EOF";
> > ...
> > EOF

>
> 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

 
Reply With Quote
 
 
 
 
Mark Tarver
Guest
Posts: n/a
 
      12-02-2006
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

Mirco Wahab wrote:
> Thus spoke Mark Tarver (on 2006-12-03 00:42):
>
> > But it still does not work - and with the same message.

>
> Your original error message was:
>
> "Software error:
> Can't open mailprog."
>
> This one is nowhere contained in your script.
> Are you really sure to test the correct perl/cgi file?
>
> M.


 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      12-03-2006
Mark Tarver wrote:
>
> 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
--
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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      12-03-2006
Mark Tarver <> wrote:


> 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.


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Mark Tarver
Guest
Posts: n/a
 
      12-03-2006
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




John W. Krahn wrote:
> Mark Tarver wrote:
> >
> > 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
> --
> 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


 
Reply With Quote
 
Mumia W. (reading news)
Guest
Posts: n/a
 
      12-03-2006
On 12/02/2006 07:27 PM, Mark Tarver wrote:
> 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.


> close(MAIL);
>
> produces
>
> Can't open mailprog.
>
> Mark
>
>
>
>




--



 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      12-03-2006
Mark Tarver wrote:
> 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
>>> 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


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
 
Reply With Quote
 
Mark Tarver
Guest
Posts: n/a
 
      12-03-2006

> 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

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      12-03-2006
"Mark Tarver" <> wrote in
news: ups.com:

>
>> 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.


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 <>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc...uidelines.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a script from another script and other script does notdo busy wait. Rajat Python 3 01-08-2010 02:05 PM
Why :: ? Why not : ? Why not . ? <- less clutter ?!? Skybuck Flying C++ 16 08-25-2007 09:48 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57