[Perl] Form and CGI to send it help

Oren Gozlan oren at mobixell.com
Tue Aug 27 05:37:32 PDT 2002


Hi .... i a newbe in perl ... trying to build a form  and a cgi to get 
the from inputs and sent it to $to ...
i can send the form ... but .... the attachemnt is allway .JPEG (i don't 
know how to get the file type from the form ... ) and it is imposible to 
open it .
Help ... ???

##########################################################################################
HTML Form :
############

<form name="MMS" ENCTYPE="multipart/form-data" method="post" 
action="/cgi-bin/form.pl"> <br>
           To:  <input type="text" name="to"> <br>
           From:         <input type="text" name="from"> <br>
        <br>
       Subject: <input type="text" name="message" size="40"> <br>
       Message: <input type="text" name="body" size="40"> <br>
        <br>
            file 1:<input type="file" name="file1"> <br>
               <br>
                      <input type="submit" value="send">    
                  </form>
            </center>
        </body>
    </html>
###################################################################
AND The form . pl :
###################

#!/usr/bin/perl
use CGI;
use Net::SMTP;
use MIME::Entity;

my ( $query, $from, $subject, $to, $file1, $body, );

$query    = new CGI;
chomp( $from     = $query->param('from')    );
chomp( $subject  = $query->param('message') ) || 'No Subject';
chomp( $to       = $query->param('to')      );
chomp( $body     = $query->param('body')    );
chomp( $file1    = $query->param('file1')   );


print $query->header;

unless ($from) {
    print "Please fill in your email and try again";
    exit;
}

unless ($to) {
    print "Please fill in your friend's phone number and try again";
    exit;
}

  $out_entity = MIME::Entity->build(
                                     'Type'    => 'multipart/mixed',
                                     'From'    => $from,
                                     'Subject' => $subject,
                                     'To'      => $to,
                                     'X-Mailer'=> 'Mobixell 
eMail->MMS-SEND GW/1.0 - Debian/sid'
                                    );

  $out_entity->attach( 'Encoding' => 'quoted-printable',
                       'Data'     => $body );

  if ( $file1 ne '' ) {
          $out_entity->attach( 'Data'        => $file1,
                               'Type'       => 'image/jpeg',
                               'Disposition' => "attacment",
                               'Encoding'  => "base64");
  }

my $smtp;
     $smtp = Net::SMTP->new('localhost');

     $smtp->mail($from);
     $smtp->to($to);
     $smtp->data();
     $smtp->datasend( $out_entity->stringify );
     $smtp->dataend();
     $smtp->quit;

print "Mail is flying away to $to...";





More information about the Perl mailing list