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

Dear monks,

I use this below cgi form after submitting the mail entry detail form. Here, if only send message means it properly sending no problem. If i use attachments in the form also it sending from my local system cgi file. I use this cgi files in the my webserver and i attached the attachment in the local server means it's not working. How can i change the code please provide.

#!/usr/bin/perl + use CGI qw(:standard); use MIME::Lite; + my $q = CGI->new; + print $q->header; + print $q->start_html(-title=>"second document"); + my $from = $q->param('textfield1'); my $to = $q->param('textfield2'); my $cc = $q->param('textfield3'); my $bcc = $q->param('textfield4'); my $subject = $q->param('textfield5'); my $data = $q->param('textarea1'); + + $msg = MIME::Lite->new( + From => $from, + To => $to, + Cc => $cc, + Bcc => $bcc, + Subject => $subject, + Data => $data + ); + $msg->attach( Type => "AUTO", Path => "/home/test/perl.ppt", Filename => "perl.ppt" + ); + $msg->send; + print "Mail has been send to $to OK"; + print $q->end_html;

Replies are listed 'Best First'.
Re: How to attach the attachments?
by johnnywang (Priest) on Jun 03, 2005 at 05:40 UTC
    I just did a mail attachment script a couple of days ago, also had some strange problems with attachments, eventually the following worked:
    my $msg = MIME::Lite->new( From => $from, To => $to, Subject => $subject, Type => "multipart/mixed" ); $msg->attach(Type => "Text", Data => $data); $msg->attach(Type => "application/pdf", Path =>"/tmp/test.pdf", Filename =>"test.pdf", Disposition =>"attachment" ); # Somehow the direct send() didn't work for me # so I resorted to the old fashioned way open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL $msg->as_string; close(MAIL);
Re: How to attach the attachments?
by monarch (Priest) on Jun 03, 2005 at 04:04 UTC
    Are any errors being produced? What if you run this from the command line e.g.:
    perl -w script.pl 'textfield1=test@test.com&textfield2=destination@t +o.com&textfield3=&textfield4=&textfield5=BlankSubject&textarea1=MyDat +a'

    ..or even try it with the debugger from the command line..

    perl -d script.pl 'textfield1=test@test.com&textfield2=destination@t +o.com&textfield3=&textfield4=&textfield5=BlankSubject&textarea1=MyDat +a'

    I guess I am most curious to know if the file /home/test/perl.ppt exists on your local and web servers? Perhaps add:

    die( "No such file" ) if ( ! -e "/home/test/perl.ppt" );
Re: How to attach the attachments?
by Fletch (Bishop) on Jun 03, 2005 at 04:14 UTC

    Not that it's relevant to your question (which anyhow something Yoda might say resembles . . . ), but using an unvalidated value provided by a user for either the from or to addresses is a Bad Idea®.

    --
    We're looking for people in ATL

Re: How to attach the attachments?
by gube (Parson) on Jun 03, 2005 at 04:26 UTC

    I have run a program no errors in cgi file, my files are in webserver. I attached the attachment in my local system it not yet send that is the problem.

      Hi,
      Can you add an eval block to your code and try printing $@ and also $! what it prints?
      You may be attempting to download a file attachment too large for your mail to handle. Email was never designed for file transfer, and therefore doesn't accomplish this efficiently. If you would like to send a large file to someone, we would recommend uploading it to your Virtual Server and making it available for download through HTTP or FTP.
      Remember there will be at least two copies of any file attachments. If your virtual server does not have enough extra space to hold two copies of an email, it cannot be delivered, and if your virtual server does not have enough extra space to hold two copies of your mailbox, you cannot download the mail.
      Also will these be helpful to you
      http://perl.about.com/od/emailandperlscripts/l/aa042302b.htm
      http://www.tek-tips.com/faqs.cfm?fid=2901
      http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=196&lngWId=6
      Regards
      Is sendmail running on your local system?

      i.e. if you type:

      echo -ne "Subject:Hello2\n\n" |sendmail gube@localprovider.com
      do you get an email?
Re: How to attach the attachments?
by kwaping (Priest) on Jun 03, 2005 at 14:43 UTC
    It might be a permissions issue. Make sure your server daemon's user (usually "nobody") can navigate to and read "/home/test/perl.ppt". Let me know if you need any specific commands to check and change permissions.