Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Using MIME::Lite

by kidd (Curate)
on Jul 15, 2002 at 18:45 UTC ( #181875=perlquestion: print w/replies, xml ) Need Help??
kidd has asked for the wisdom of the Perl Monks concerning the following question:


Can someone tell me why doesnt this work...

my $msg = MIME::Lite->new( From =>$Input{'email'}, To =>$Input{'sender'}, Subject =>'New message', Type =>'multipart/mixed' ); $msg->attach(Type =>'TEXT', Data =>"$Input{'message'}" ); open(FILE, "attach.txt"); my @lines = <FILE>; close(FILE); foreach my $line(@lines){ $msg->attach(Type =>'image/gif', Path =>"/u619/be/bon/uploads/$line", Filename =>"$line", Disposition => 'attachment' ); } $msg->send; print "Content-type: text/html\n\n"; print "<h1>MAIL SENT</h1>";

What I have in my "attach.txt" text are the file names of pictures...the two of them in .jpg...

I know it's not a problem with the location of the library, and it isnt the sendmail path...

It would be great if you could tell me what Im doing wrong...


Replies are listed 'Best First'.
Re: Using MIME::Lite
by aseidas (Beadle) on Jul 15, 2002 at 19:49 UTC
    Removed incorrect post here

    kidd, what are the permissions/ownership of the main.jpg file your are trying to attach?

    UPDATE:Sorry kidd disregard my post, thanks for the correction chromatic. -Aseidas

      Does that actually work? I have a hard time believing the original poster has files called, literally, '$line'.

      To kidd, the reason your program doesn't work is because there's a bug. You need to look in your error logs, run the script from the command line, or use CGI::Carp to display the error message to the browser. Without the information Perl's perfectly willing to give you, it's tremendously difficult to do anything other than guessing what and where the error is.

        When running the script with CGI::Carp I got this error...

        Software error:
        /u619/be/bon/uploads/main.jpg : not readable
Re: Using MIME::Lite
by lachoy (Parson) on Jul 15, 2002 at 21:07 UTC

    A tip: generate some information in the error log so you can tell what's going on. For instance, you might add a message to the error log using warn with something like:

    foreach my $line(@lines){ warn "Trying to attach file [$line]"; $msg->attach(Type =>'image/gif', Path =>"/u619/be/bon/uploads/$line", Filename =>"$line", Disposition => 'attachment' ); } $msg->send;

    If you did this, you might find that your filename has a newline in it, which may prevent MIME::Lite from locating it properly. Try adding the following line after you close the file:

    chomp @lines;

    The following example of MIME::Lite usage may also be helpful: RE: sending email

    M-x auto-bs-mode

Re: Using MIME::Lite
by Fastolfe (Vicar) on Jul 15, 2002 at 19:00 UTC
    Please define "doesn't work".
      I get a 500 Error...and It doesnt send any mails...
Re: Using MIME::Lite
by Beatnik (Parson) on Jul 16, 2002 at 01:29 UTC
    are you chomping $line? Does your script have access to those files? Remember access permissions for CGI scripts can be pretty strict. Check to see if permissions for those files are correct if you are sure the directory permissions are correct. Print the HTTP header ASAP (I mean at the top of the file, after the shebang) and altho CGI might seem overkill here (because of the huge size), there are ways to only load the header and there's nothing like a good habbit to keep your code from turning buggy.

    ...Perl is like sex: if you're doing it wrong, there's no fun to it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://181875]
Approved by broquaint
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-05-22 18:03 GMT
Find Nodes?
    Voting Booth?