in reply to Re: Re: Re: Re: Re: Using MIME-Lite to send attachment
in thread Using MIME-Lite to send attachment

Hello. I have one more question. Thanks for all your help so far! I'm still having problems with this script. I think I have it all working except that I now get the error message:
Can't call method "attach" without a package or object reference
Can you tell me what this means?

Rob

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Using MIME-Lite to send attachment
by tachyon (Chancellor) on Apr 13, 2004 at 02:14 UTC

    What this means is pretty much what it says! You may well find adding the line 'use diagnostics;' to your code helpful as the diagnostics module will pull some details from the perldocs for you. For example:

    use diagnostics; 0->my_method(); __DATA__ Can't call method "my_method" without a package or object reference at (F) You used the syntax of a method call, but the slot filled by t +he object reference or package name contains an expression that retur +ns a defined value which is neither an object reference nor a package n +ame. Something like this will reproduce the error: $BADREF = 42; process $BADREF 1,2,3; $BADREF->process(1,2,3); Uncaught exception from user code: Can't call method "my_method" without a package or object referenc +e at script line 3

    So above you see an example that generates your error. Diagnostics have expanded the error message (in this case it is not the best explanation I have ever seen but....)

    So the error is I called the method 'my_method' on the value 0. You can't call a method on 0 or an undefined value or in fact anthing that is not a blessed object that supports that method. The error has occurred because your Mime::Lite object is not defined for some reason. Without seeing the code you are currently working with that is all I can say.

    cheers

    tachyon

Re: Re: Re: Re: Re: Re: Re: Using MIME-Lite to send attachment
by tachyon (Chancellor) on Apr 13, 2004 at 03:16 UTC

    Here is an example that works on my Win32 box:

    use MIME::Lite; my $smtp = 'mail.trump.net.au'; # (typically your ISPs SMTP server) my $from = 'james.freeman@smartsurf.org'; my $to = $from; my @cc = qw( ); # add addresses here to Cc, space separated my $sbj = 'A test with attachment'; my @cc = ( "Cc" => (join ',', @cc) ) if @cc; my $msg = MIME::Lite->new( From => $from, To => $to, @cc, Subject => $sbj, Type =>'multipart/mixed', ) or die "Could not create Mime::Lite object!"; $msg->attach( Type =>'TEXT', Data =>"Here's the file you wanted" ); $msg->attach( Type =>'image/gif', # often 'application/octet-stre +am' Path =>"C:\\background.gif", # full path to file Filename =>'background.gif' # name we want to use in email +for file ); #print $msg->as_string; $msg->send_by_smtp( $smtp) or die "Could not send mail $!\n";

    cheers

    tachyon