Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Mail::Sender giving me an error

by donkeykong (Novice)
on Aug 06, 2009 at 21:13 UTC ( [id://786590] : perlquestion . print w/replies, xml ) Need Help??

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

Hi Perl Monks, I could use some of your words of wisdom once again. I am using mail::sender as follows:
use Mail::Sender; sub send_mail { my $sender = Mail::Sender->new({ smtp => 'xxxx', from => 'dk@dk.com', fake_from => 'Ping Service' }); $sender->MailFile( { to => 'diki@dk.com', subject => $subject, msg => $body }); $sender->Close; }
I keep getting this error when I run it:
Can't call method "MailFile" without a package or object reference at +script.pl on line 36
I just installed the module, and verified its existence, and the script runs if I don't call this sub. I've also looked at a bunch of other sample code with this exact format. Any help is appreciated.

Replies are listed 'Best First'.
Re: Mail::Sender giving me an error
by Anonymous Monk on Aug 06, 2009 at 21:18 UTC
    sub send_mail { use Mail::Sender; my $sender = Mail::Sender->new({ on_errors => 'die', smtp => 'xxxx', from => 'dk@dk.com', fake_from => 'Ping Service' }); $sender->MailFile( { to => 'diki@dk.com', subject => $subject, msg => $body }); $sender->Close; }
      Thanks a lot! Why is it that I can't call 'use Mail::Sender' outside of the sub?
        Why is it that I can't call 'use Mail::Sender' outside of the sub?

        Who said you can't? I just like things neat

        send_mail('subject', 'body'); sub send_mail { use Mail::Sender; my( $subject, $body ) = @_; my $sender = Mail::Sender->new({ on_errors => 'die', smtp => 'xxxx', from => 'dk@dk.com', fake_from => 'Ping Service' }); $sender->MailFile( { to => 'diki@dk.com', subject => $subject, msg => $body }); $sender->Close; }
Re: Mail::Sender giving me an error
by Jenda (Abbot) on Aug 09, 2009 at 09:57 UTC

    Apparently the Mail::Sender->new(...) failed. You should check that and print $Mail::Sender::Error to find out why.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

      on_errors => 'die', covers that :)
Re: Mail::Sender giving me an error
by bichonfrise74 (Vicar) on Aug 06, 2009 at 22:58 UTC
    That is strange. I tested your exact code on my machine and it did not complain about anything.