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

Hi Monks, And for my next question! I'm trying to use Mail::SendMail to send mail on a windows server that I only have basic ftp access to, so can't install anything on it only put things on locally. The hosts recommend that I use this one. After much reading I found out how to 'use' it correctly (I think!) but it now doesn't know what I mean when I call 'new'. Here's my code:-
#!/usr/bin/perl use CGI; use warnings; use strict; use lib "Mail::SendEasy"; use CGI::Carp qw/fatalsToBrowser/; my $query = new CGI; print $query->header(); print "\@INC is @INC\n<br>"; my $mail = new Mail::SendEasy( smtp => 'localhost' , user => 'foo' , pass => 123 , ) ; my $status = $mail->send( from => 'sender@foo.com' , from_title => 'Foo Name' , reply => 're@foo.com' , error => 'sarah@sarahsfleeces.co.uk' , to => 'sarah@sarahsfleeces.co.uk' , #cc => 'recpcopy@domain.foo' , subject => "MAIL Test" , msg => "The Plain Msg..." , html => "<b>The HTML Msg...</b>" , msgid => "0101" , ) ; if (!$status) { print $mail->error ;} print "it works!";
The error message is:-
Can't locate object method "new" via package "Mail::SendEasy" (perhaps + you forgot to load "Mail::SendEasy"?) at d:\domains\mysite.co.uk\www +root\cgi-bin\Send_Details.pl line 35.
I'm sure this is just a simple syntax error on my part, maybe to do with how I've 'use'd the module SendEasy but after hours of reading on the net and on here that's the only way I've found for it to not cause an error on that line... any suggestions gratefully received if that's the wrong way to do it. I appreciate I could load it on locally as another option but I don't like giving up that easily! Many thanks Sarah

Replies are listed 'Best First'.
Re: Why won't call to SendEasy 'send' sub won't work?
by Corion (Patriarch) on Feb 04, 2009 at 13:01 UTC

    This line looks fishy:

    use lib "Mail::SendEasy";

    as that line implies that your host has a directory Mail::SendEasy, under which there is a file Mail/SendEasy.pm. But if that is what your host says to you, all I can recommend is using an absolute directory name instead of using a relative directory name, like use lib "/home/Stoney/Mail::SendEasy/";

    You need to actually use the module before you can use routines from the module:

    use Mail::SendEasy;

    will do that.

      Hi thanks for this, I don't know the absolute directory for SendEasy but will try to find out... I've added the line after the other 'use's:-
      use Mail::SendEasy;
      and have gone back to my original error which lead me to put the quotes and lib bit in the 'use' line:-
      Can't locate Mail/SendEasy.pm in @INC (@INC contains: Mail::SendEasy d +:/perl/site/lib d:/perl/lib .) at d:\domains\sarahsfleeces.co.uk\wwwr +oot\cgi-bin\Send_Details.pl line 8. BEGIN failed--compilation aborted at d:\domains\sarahsfleeces.co.uk\ww +wroot\cgi-bin\Send_Details.pl line 8.

        So it would seem that you need to go back to Difficulty in sending mail with Activestate Perl 5.10 on a windows server, and the answers you received there, and possibly, again, consult with your hosting administrator as to where the Mail::SendEasy module is installed. Note that Mail::SendEasy is different from Mail::SendMail which you mention in your thread root, so you may want to check and clarify with your hosting support or the mails you sent them about whether the recommended solution is Mail::SendMail or Mail::SendEasy.

Re: Why won't call to SendEasy 'send' sub won't work?
by locked_user sundialsvc4 (Abbot) on Feb 04, 2009 at 14:36 UTC

    Does “use FindBin” work in that environment?

      If I substitute use Mail::SendMail; for use FindBin; it produces this error:- Can't load 'd:/perl/lib/auto/Win32/Win32.dll' for module Win32: load_file:Access is denied at d:/perl/lib/DynaLoader.pm line 202. at d:/perl/lib/Cwd.pm line 671 Compilation failed in require at d:/perl/lib/Cwd.pm line 671. BEGIN failed--compilation aborted at d:/perl/lib/FindBin.pm line 206. BEGIN failed--compilation aborted at d:/perl/lib/FindBin.pm line 206. Compilation failed in require at d:\domains\sarahsfleeces.co.uk\wwwroot\cgi-bin\Send_Details.pl line 11. BEGIN failed--compilation aborted at d:\domains\sarahsfleeces.co.uk\wwwroot\cgi-bin\Send_Details.pl line 11.