in reply to Software Error: Close.pm

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

Replies are listed 'Best First'.
Re: Re: Software Error: Close.pm
by Nickd_69 (Novice) on Aug 22, 2003 at 00:51 UTC
    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
        Hey bob thanks for your previous response as it helped HEAPS!! I am now recieving this error which I am not sure why??
        syntax error at enquiry02.pl line 25, near "$mailer open"


        It doesn't like that line were you open the headers. Here is my code so far. I reckon it looks ok but I only a newbie so it properly aint. Can you or anyone see what I did or am doing wrong in a simple terms as you can??? Thanks fellas
        #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer; my $query = CGI->new(); my @param = qw( Title Name Position School Address Suburb State PCode Email Tel Fax Comments ); my $mailer = new Mail::Mailer; my %headers = ( To => 'test@tester.com', From => 'test', Subject => 'test send stuff', ); $mailer open(\%headers); my $body = ( print $mailer $query->param('Title'), print $mailer $query->param('Name'), print $mailer $query->param('Position'), print $mailer $query->param('School'), print $mailer $query->param('Address'), print $mailer $query->param('Suburb'), print $mailer $query->param('State'), print $mailer $query->param('PCode'), print $mailer $query->param('Email'), print $mailer $query->param('Tel'), print $mailer $query->param('Fax'), print $mailer $query->param('Comments'), ); print $mailer $body; $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');