×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Sending a file as an attachment

Sending a file as an attachment

Sending a file as an attachment

(OP)
Im using a formmail script to send pdf documents from a form.  The user selects the file to send, then it is supposed to send the file as an attachment.

The problem is, that it sends the file as (i think) MIME encoded text.  I want it to send the file as an attachment.

Here is the send mail function from the script:

sub send_mail {
   if ($form_letter ne "") {
      push (@files,$form_letter);
   }
   foreach $file (@files) {
      if (-e "$filebase/$file") {
         open(MAIL,"¦$mailprog -t");
         
         print MAIL "To: $email ($realname)\n";
         print MAIL "From: $fromaddr ($fromname)\n";
         if ($organization) {
            print MAIL "Organization: $organization\n";
         }
         else {
            print MAIL "Organization: Auto sent file\n";
         }
         print MAIL "Subject: $file\n";
         print MAIL "X-Courtesy-Of: SendIt! 1.0\n\n";
         open(INPUT,"$filebase/$file")¦¦&error;
         while (<INPUT>) {
         print MAIL "From: $fromaddr ($fromname)\n";
         if ($organization) {
            print MAIL "Organization: $organization\n";
         }
         else {
            print MAIL "Organization: Auto sent file\n";
         }
         print MAIL "Subject: $file\n";
         print MAIL "X-Courtesy-Of: SendIt! 1.0\n\n";

* this is the bit which 'attaches' the file.  But it opens it for INPUT and writes it line by line I think...*

         open(INPUT,"$filebase/$file")¦¦&error;
         while (<INPUT>) {
            chop $_;
            print MAIL $_,"\n";
         }
         close (INPUT);
*How can I make it attach the file, not write it?*

         close (MAIL);
      }
      else {
         print "Content-type: text/html\n\n";
         print "<head><title>Sorry</title></head>\n";
         print "<body bgcolor=ffffff><center><h1>Sorry</h1></center>\n";
         print "Sorry, your request for files could not be completed\n";
         print "because at least one of the files was not available.<p>\n"...  blah blah blah etc.

RE: Sending a file as an attachment

Sounds like something you have to dig into the email protocol to figure out.  Not a pretty prospect.  You could try disecting an email with an attachment (an Outlook Express .eml file in Notepad for instance) to figure out what makes it an attachment rather than a part of the body.

Why not try the backdoor?  Output an html formatted email with a javascript, an ssi, or perl script to your pdf.  Or even just a link (to make things overly simple).

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Sending a file as an attachment

(OP)
The pdf's are already going to be on the site for download, the idea is that the user can enter an email address and then just click to send the files as attachments.  I would consider sending an email with a link as a last resort, but I think I'll try and look at email in notepad like you suggest...  I was hoping there would be a simpler way!

RE: Sending a file as an attachment

Well, reviewing the sendmail documentation is by far NOT the easier way ;)  But you could give that a try.

Oh, I think I might know what the problem is... did you put a single . on the last line of the body?  If not, it will continue using the input as body text.  If you supply the dot, then the body will finish, but the files afterwards should show up as attachments.

Try it.

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close