#!/usr/local/bin/perl

%names = (
  'n1' => '"СТАРАЯ═ДЕВА═МАРИЯ"',
  'n2' => '"КНИГА ПИСЕМ"',
  'n3' => 'Альманах "ТЕНИ СТРАННИКА"',
);

use CGI qw(:all);

$body = '';

if( param('send') ){
   foreach $key (keys %names){
      $n = param("$key");
      $body .= "  $names{$key} - $n шт.\n" if( $n );
   }
}

if( $body ){
   $address = param('address');
   $body = qq'
Уважаемый Владимир Михайлович,

Прошу Вас выслать мне по адресу

$address

следующие книги:
$body

Спасибо.
';

   &send_mail( $body, 'lipunov@sai.msu.su' );

   print header(), start_html();
   print qq'
<CENTER><H1>
Заказ послан.
</H1></CENTER>

';
   print end_html();
}else{
   print redirect(referer());
}


##########################################################
sub send_mail {
  my( $mess ) = shift;
  my( $to ) = join( ' ', @_ );

  open MAIL, qq'| /bin/mail -s "Заказ" $to';
  print MAIL "\n",$mess,"\n";
  close MAIL;
}
