PDA

View Full Version : Problem getting field from form into e-mail



Tiradientes
03-01-2010, 09:25 PM
When I SUBMIT a POST form from HTML, all I get in the e-mail that is sent to me are the names of the fields, but the field data is not copied. Any help would be greatly appreciated.

First, the simple HTML code: [code]
<form action="http://my.domain/bin/forms.cgi" method="POST">
Personal name: <input type='text' name="firstname" />
Family name: <input type='text' name="familyname" />
<input type="submit" value=" Send " />
</form>

Next, the corresponding CGI: [code]
#!/usr/bin/perl - -
use Net::SMTP;
$smtp = Net::SMTP->new('smtp.my.domain', Timeout => 60);
$smtp->mail('mymail@nanzan-u.ac.jp');
$smtp->recipient('mymail@nanzan-u.ac.jp');
$firstname = ('firstname');
$familyname = ('familyname');
$smtp->data;
$smtp->datasend("From: heisig\@nanzan-u.ac.jp\n");
$smtp->datasend("To: heisig\@nanzan-u.ac.jp\n");
$smtp->datasend("Subject: Special-order book\n");
$smtp->datasend("\n");

$smtp->datasend("$firstname familyname") ;
$smtp->datasend("\n") ;
$smtp->dataend;
$smtp->quit;
print "Content-type:text/html\n\n";
print "done.\n";

alienspaces
03-09-2010, 04:49 AM
#!/usr/bin/perl

use strict;
use warnings;

use Net::SMTP;
use CGI;

my $cgi = new CGI;

#
# instantiate smtp object
#
my $smtp = Net::SMTP->new('smtp.my.domain', Timeout => 60);
$smtp->mail('mymail@nanzan-u.ac.jp');
$smtp->recipient('mymail@nanzan-u.ac.jp');

#
# assign form fields to variables
#
my $firstname = $cgi->param( -name => 'firstname');
my $familyname = $cgi->param( -name => 'familyname');

#
# send data
#
$smtp->data();
$smtp->datasend("From: heisig\@nanzan-u.ac.jp\n");
$smtp->datasend("To: heisig\@nanzan-u.ac.jp\n");
$smtp->datasend("Subject: Special-order book\n");
$smtp->datasend("\n");

#
# data assigned to variables from form fields
#
$smtp->datasend("$firstname $familyname") ;

$smtp->datasend("\n") ;
$smtp->dataend();
$smtp->quit;

#
# display response
#
print $cgi->header();
print $cgi->start_html() .
'All done' .
$cgi->end_html();

exit(0);