Nickd_69 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl monks,

I have recently made a script to send form values to an email but my web server does not have the module that I require and I cannot seem to find it on CPAN or google search.

Does anyone have any ideas where I could find this module or why it is giving me this error?

Here is the Error:
Software error:
[Fri Aug 22 09:53:15 2003] enquiry02.pl:
 Can't locate Mail/Mailer/close.pm in @INC
 (@INC contains:
    /usr/libdata/perl/5.00503/mach
    /usr/libdata/perl/5.00503
    /usr/local/lib/perl5/site_perl/5.005/i386-freebsd
    /usr/local/lib/perl5/site_perl/5.005
  )
 at (eval 5) line 3.

And here is my code:

#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer (qw/close/); my $query = CGI->new(); my @param = qw( Title Name Position School Address Suburb State PCode Email Tel Fax Comments ); my $mailer = Mail::Mailer->new; $mailer->open({ To => 'test@tester.com, From => 'tester', Subject => 'results of submit', }); $mailer = $query->param('Title'); $mailer = $query->param('Name'); $mailer = $query->param('Position'); $mailer = $query->param('School'); $mailer = $query->param('Address'); $mailer = $query->param('Suburb'); $mailer = $query->param('State'); $mailer = $query->param('PCode'); $mailer = $query->param('Email'); $mailer = $query->param('Tel'); $mailer = $query->param('Fax'); $mailer = $query->param('Comments'); $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');

Thanks in advance to any perl monks that help. Cheers.

edited by ybiC: HTML-encode square brackets in error message

Replies are listed 'Best First'.
Re: Software Error: Close.pm
by bobn (Chaplain) on Aug 22, 2003 at 00:21 UTC

    Here is an excerpt of the synopisis, straight from perldoc Mail::Mailer:

    use Mail::Mailer; $mailer->open(\%headers); print $mailer $body; $mailer->close;

    $mailer is a file handle object you print to, not variable you assign to. Unfortunately, after the assignment

    $mailer = $query->param('Title');
    , it was simply a string, so anytime thereafter, $mailer->close; was doomed to fail.

    What you really wanted was (probably - untested): print $mailer query->param('Title'); etc.

    --Bob Niederman, http://bob-n.com
      Hey bobn,

      Tried what you suggested by adding the print command but how do I use these lines that you gave me?
      $mailer->open(\%headers); print $mailer $body;
      When I put these in it says: Global symbol "$body" requires explicit package name

      Does this mean I have to declare it first using my?

      Sorry cause this is probably a dumb question but still trying to learn. Thanks

        I was just quoting what was in the perldoc.

        Part of the problem is I excerpted too fast leaving out my $mailer = new Mail::Mailer; - see below.

        $mailer->open(\%headers); is giving the open method a reference to the hash %headers, so the following are equivalent:

        my $mailer = new Mail::Mailer; my %headers = ( To => 'test@tester.com, From => 'tester', Subject => 'results of submit', ); $mailer open(\%headers);
        and
        my $mailer = new Mail::Mailer; $mailer->open({ To => 'test@tester.com, From => 'tester', Subject => 'results of submit', });

        Those two are equivalent because the first creates a hash then hands open() a reference to it using the backslash to take the reference. The second creates a hashref in place by enclosing the contents of the hash in curlie brace {} instead of the normal ().

        And yes the error message 'Global symbol "$body" requires explicit package name' does mean you're using strict and need to declare the variable using my. Congratulation on using strict - it's a very good habit to get into.

        Having used the open() method, you would then say:

        print $mailer $query->param('Title'); print $mailer $query->param('Name'); print $mailer $query->param('Position'); # etc for rest of params $mailer->close;

        All code here is untested, BTW.

        --Bob Niederman, http://bob-n.com