[Perl] Form and CGI to send it help

Oren Gozlan oren at mobixell.com
Tue Aug 27 06:03:17 PDT 2002


Hi and Thnx for the 1st help ...

my second question ...
is the $entity (build and attach ) are ok ? (with the changes from 
Shlomi's reply)

Shlomi Fish wrote:

>Your problem is in handling the file. $q->param() will return you a handle
>(you should not chomp it!, and it is pointless for the other variables as
>well, albeit you should make sure they are valid and that someone is not
>trying to maliciously put invalid input their).
>
>Handling the handle is something like that:
>
>my $file = $q->param("myfile");
>my $path = "$file";
>my $contents = join("", <$file>);
>my $filename = $path;
>$filename =~ s!^.*[/\\]!!;
>
>For more information refer to the CGI man page.
>
>Regards,
>
>	Shlomi Fish
>
>On Tue, 27 Aug 2002, Oren Gozlan wrote:
>
>  
>
>>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...";
>>
>>
>>_______________________________________________
>>Perl mailing list
>>Perl at perl.org.il
>>http://www.perl.org.il/cgi/listinfo/perl
>>
>>    
>>
>
>
>
>----------------------------------------------------------------------
>Shlomi Fish        shlomif at vipe.technion.ac.il
>Home Page:         http://t2.technion.ac.il/~shlomif/
>Home E-mail:       shlomif at iglu.org.il
>
>He who re-invents the wheel, understands much better how a wheel works.
>
>_______________________________________________
>Perl mailing list
>Perl at perl.org.il
>http://www.perl.org.il/cgi/listinfo/perl
>
>  
>






More information about the Perl mailing list