Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending a file as an attachment

Status
Not open for further replies.

Streetdaddy

Programmer
Jun 10, 1999
161
AU
Im using a formmail script to send pdf documents from a form.&nbsp;&nbsp;The user selects the file to send, then it is supposed to send the file as an attachment.<br><br>The problem is, that it sends the file as (i think) MIME encoded text.&nbsp;&nbsp;I want it to send the file as an attachment.<br><br>Here is the send mail function from the script:<br><br>sub send_mail {<br>&nbsp;&nbsp;&nbsp;if ($form_letter ne &quot;&quot;) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push (@files,$form_letter);<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;foreach $file (@files) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (-e &quot;$filebase/$file&quot;) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(MAIL,&quot;¦$mailprog -t&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;To: $email ($realname)\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;From: $fromaddr ($fromname)\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($organization) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;Organization: $organization\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;Organization: Auto sent file\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;Subject: $file\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;X-Courtesy-Of: SendIt! 1.0\n\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(INPUT,&quot;$filebase/$file&quot;)¦¦&error;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (&lt;INPUT&gt;) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;From: $fromaddr ($fromname)\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($organization) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;Organization: $organization\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;Organization: Auto sent file\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;Subject: $file\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL &quot;X-Courtesy-Of: SendIt! 1.0\n\n&quot;;<br><br>* this is the bit which 'attaches' the file.&nbsp;&nbsp;But it opens it for INPUT and writes it line by line I think...*<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(INPUT,&quot;$filebase/$file&quot;)¦¦&error;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (&lt;INPUT&gt;) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chop $_;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print MAIL $_,&quot;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close (INPUT);<br>*How can I make it attach the file, not write it?*<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close (MAIL);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Content-type: text/html\n\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;head&gt;&lt;title&gt;Sorry&lt;/title&gt;&lt;/head&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;body bgcolor=ffffff&gt;&lt;center&gt;&lt;h1&gt;Sorry&lt;/h1&gt;&lt;/center&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Sorry, your request for files could not be completed\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;because at least one of the files was not available.&lt;p&gt;\n&quot;...&nbsp;&nbsp;blah blah blah etc.<br>
 
Sounds like something you have to dig into the email protocol to figure out.&nbsp;&nbsp;Not a pretty prospect.&nbsp;&nbsp;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.<br><br>Why not try the backdoor?&nbsp;&nbsp;Output an html formatted email with a javascript, an ssi, or perl script to your pdf.&nbsp;&nbsp;Or even just a link (to make things overly simple).<br><br>Sincerely,<br><br>Tom Anderson<br>CEO, Order amid Chaos, Inc.<br><A HREF=" TARGET="_new">
 
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.&nbsp;&nbsp;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...&nbsp;&nbsp;I was hoping there would be a simpler way!
 
Well, reviewing the sendmail documentation is by far NOT the easier way ;)&nbsp;&nbsp;But you could give that a try.<br><br>Oh, I think I might know what the problem is... did you put a single . on the last line of the body?&nbsp;&nbsp;If not, it will continue using the input as body text.&nbsp;&nbsp;If you supply the dot, then the body will finish, but the files afterwards should show up as attachments.<br><br>Try it.<br><br>Sincerely,<br><br>Tom Anderson<br>CEO, Order amid Chaos, Inc.<br><A HREF=" TARGET="_new">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top