in reply to form help

use something like this....
#!/usr/bin/perl require "/web/cgi-bin/cgi-lib.pl"; &ReadParse; ### get values from html form input called email & fax $fax = $in{'fax'}; $email = $in{'email'}; $err[1] = "Please fill in all the required fields"; $domain = "your.domain.com"; ########## did they enter something? &error($err[1]) if !( $fax || $email ); &mail exit; sub error { print "Content-type: text/html\n\n"; print "<HTML><HEAD></HEAD><BODY>\n"; print "<H3>$_[0]</H3><BR>\n"; print "</BODY></HTML>\n"; exit 0; } ########## use sendmail sub mail { open (MAIL,"|/usr/lib/sendmail Me\@$domain"); print MAIL "From: script@domain.com\n"; print MAIL "To: Me\@$domain\n\n"; print MAIL "Users Fax:$fax\n"; print MAIL "Users Email:$email\n"; close MAIL; return; }

Replies are listed 'Best First'.
Re: Re: form help
by chromatic (Archbishop) on Aug 13, 2001 at 22:18 UTC
    "cgi-lib.pl" is as dead as Perl 4. CGI is a much more robust solution that takes advantages of Perl 5 features (such as references). I would instead write something like:
    #!/usr/bin/perl -wT use CGI; my $q = CGI->new(); my $fax = $q->param('fax'); my $email = $q->param('email'); print $q->header(); error('Please fill in all the required blanks') unless ($fax && $email); mail(); # print success method, redirect? sub error { print <<HTML; <HTML><HEAD></HEAD><BODY> <H3>$_[0]</H3><BR> </BODY></HTML> HTML exit 1; }
    I'd also use Mail::Send or Mail::Mailer instead of opening a pipe directly to sendmail.