Uh...yeah I was asking if I upload an image from a form via CGI how can I send an image that is an attachment to an e-mail address. Here is the relevant code :
sub SendMail { $smtp = Net::SMTP->new($mailserver); $smtp->mail ($ENV{USER}); $smtp->to($to); $smtp->data(); $smtp->datasend("To: Wheels and Deals \n"); $smtp->datasend("From: $client \n"); $smtp->datasend("Subject: $subject \n"); $smtp->datasend("\n"); $smtp->datasend("Ad Type $choice \n"); $smtp->datasend("Client Phone Number $phone \n"); $smtp->datasend("Ad Info : \n"); $smtp->datasend("Year $year "); $smtp->datasend("Make $make "); $smtp->datasend("Model $model \n"); $smtp->datasend("Description $description \n"); $smtp->datasend("Ad Phone Number $adphone \n"); $smtp->datasend("Client Will Pay by : $payment \n"); $smtp->datasend("Submitted on $datesent \n"); $smtp->datasend("Attachments : \n"); if (@attach) { foreach (@attach) { $value ++; $photoad .= $attach[$value]; $smtp->datasend("$photoad"); } } else { $smtp->datasend("none \n"); } $smtp->data(@attach); $smtp->dataend(); $smtp->quit; } ###################################################################### +### sub AttachMe { #Check to see if an allowed file type $info = uploadInfo($photo); $kind = $info->{'Content-Type'}; open (UPLOAD,">attach") || Error('File could not be opened'); my ($data, $length, $chunk); while ($chunk = read ($photo, $data, 1024)) { print UPLOAD $data; $length += $chunk; if ($length > 1048576) { $erMsg = "The file is too big. Maximum File size is 1MB"; unlink ("/c:/inetpub/wwwroot/wheelsdeals/cgi-bin/attach") || Error('Fi +le does not exist'); Error ($erMsg); exit; } } @attach = <UPLOAD>; close (UPLOAD); print "$photo of $kind was uploaded to server."; if ($erMsg) { Error ($erMsg); } } ###################################################################### +### sub Error { if ($_[0]) { print "$_[0] \n"; print "$! \n"; exit; } else { print "ERROR of Unknown type. Please contact system administrator."; print "$! \n"; exit; } }
I am able to get a picture to open, be parsed into the @attach array, then I can read the @attach array, but as garbled m achine language. My site URL is http://www.wheelsdeals.net/wswd_private_ad_form.html for the html and an example of what happens. If you have time to glance through it or test it out that would be great. Thanks OVID

In reply to Re: (Ovid) Re: Bewildered in a Land of Shiny Perls by Segreto
in thread Attaching an image to mail by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.