why does this script not work?

Discussion in 'Perl Misc' started by Mark Tarver, Dec 2, 2006.

  1. Mark Tarver

    Mark Tarver Guest

    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";
     
    Mark Tarver, Dec 2, 2006
    #1
    1. Advertising

  2. Mark Tarver

    Mark Tarver Guest

    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
     
    Mark Tarver, Dec 2, 2006
    #2
    1. Advertising

  3. Mark Tarver

    Mark Tarver Guest

    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.
     
    Mark Tarver, Dec 2, 2006
    #3
  4. 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
     
    John W. Krahn, Dec 3, 2006
    #4
  5. 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
     
    Tad McClellan, Dec 3, 2006
    #5
  6. Mark Tarver

    Mark Tarver Guest

    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
     
    Mark Tarver, Dec 3, 2006
    #6
  7. 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
    >
    >
    >
    >




    --
     
    Mumia W. (reading news), Dec 3, 2006
    #7
  8. Mark Tarver

    Joe Smith Guest

    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
     
    Joe Smith, Dec 3, 2006
    #8
  9. Mark Tarver

    Mark Tarver Guest


    > 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
     
    Mark Tarver, Dec 3, 2006
    #9
  10. "Mark Tarver" <> wrote in
    news::

    >
    >> 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/clpmisc_guidelines.html
     
    A. Sinan Unur, Dec 3, 2006
    #10
  11. Mark Tarver

    Mark Tarver Guest

    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. Sinan Unur wrote:
    > "Mark Tarver" <> wrote in
    > news::
    >
    > >
    > >> 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/clpmisc_guidelines.html
     
    Mark Tarver, Dec 3, 2006
    #11
  12. "Mark Tarver" <> wrote in
    news::

    [ *Please* do not top-post and do not quote sigs ]

    > A. Sinan Unur wrote:
    >> "Mark Tarver" <> wrote in
    >> news::

    ....

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


    > 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
     
    A. Sinan Unur, Dec 3, 2006
    #12
  13. On 12/03/2006 08:18 AM, Mark Tarver wrote:
    > 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.


    --
     
    Mumia W. (reading news), Dec 3, 2006
    #13
  14. Mark Tarver

    Dave Weaver Guest

    On 2 Dec 2006 15:53:27 -0800, Mark Tarver <> wrote:
    > 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.
     
    Dave Weaver, Dec 6, 2006
    #14
  15. Mark Tarver

    Mark Tarver Guest

    Re: why does this script not work? Mystery solved.

    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
     
    Mark Tarver, Dec 8, 2006
    #15
  16. Re: why does this script not work? Mystery solved.

    Mark Tarver <> wrote:

    > my server


    [snip]

    > is a Windows
    > machine



    > I'm moving the account to Linux.



    The world continues to be become a Better Place...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Dec 9, 2006
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jblazi
    Replies:
    5
    Views:
    448
    jblazi
    Aug 16, 2004
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    471
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    923
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,078
    Smokey Grindel
    Dec 2, 2006
  5. Replies:
    2
    Views:
    85
Loading...

Share This Page