homepage Welcome to WebmasterWorld Guest from 54.198.139.141
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Form working but data not appearing in email
pgpformmail on secure site
Lolley




msg:4261737
 3:44 pm on Feb 2, 2011 (gmt 0)

Hi

I've just created a form here: https://www.fastweb.co.uk/judithblacklock/booking_BoF.php

This form is processed by pgpformmail.pl and while the form sends and redirects ok, when I get the resulting email, there is nothing in the body of the email! I can see who the form is from, their email and the subject line. But nothing at all after that!

This is the first part of the perl with my details blanked out:


#!/usr/bin/perl
##############################################################################
# FormMail Version 1.6 #
# Copyright 1995-1997 Matt Wright mattw@worldwidemart.com #
# Created 06/09/95 Last Modified 05/02/97 #
# Matt's Script Archive, Inc.: http://www.worldwidemart.com/scripts/ #
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 1995-1997 Matthew M. Wright All Rights Reserved. #
# #
# FormMail may be used and modified free of charge by anyone so long as this #
# copyright notice and the comments above remain intact. By using this #
# code you agree to indemnify Matthew M. Wright from any liability that #
# might arise from its use. #
# #
# Selling the code for this program without prior written consent is #
# expressly forbidden. In other words, please ask first before you try and #
# make money off of my program. #
# #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium.In all cases copyright and header must remain intact #
##############################################################################
# Modified to encrypt output with PGP (pref v5.0i) #
# by Andrew Spiers, Namecity (andy@namecity.com) 13th April 1999 #
##############################################################################

$mailprog = '/usr/sbin/sendmail';
$pgpecmd = '/usr/local/bin/gpg';
$ENV{'HOME'} = '/home/gpg';
$filedate = `/bin/date +%s`;
chomp $filedate;
$pgptmp = "/tmp/" . $filedate . "-pgptmp";

@referers = ('www.mywebsite.co.uk', 'my.ip.add.ress');

print STDERR "Home directory: $ENV{'HOME'} \n";

##############################################################################

# Check Referring URL
&check_url;

# Retrieve Date
&get_date;

# Parse Form Contents
&parse_form;

# Check Required Fields
&check_required;

# Return HTML Page or Redirect User
&return_html;

# Send E-Mail
&send_mail;

sub check_url {

# Localize the check_referer flag which determines if user is valid. #
local($check_referer) = 0;

# If a referring URL was specified, for each valid referer, make sure #
# that a valid referring URL was passed to FormMail. #

if ($ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) {
$check_referer = 1;
last;
}
}
}
else {
$check_referer = 1;
}

# If the HTTP_REFERER was invalid, send back an error. #
if ($check_referer != 1) { &error('bad_referer') }
}

sub get_date {

# Define arrays for the day of the week and month of the year. #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');

# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;

# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year at $time";

}

sub parse_form {

# Define the configuration associative array. #
%Config = ('recipient','', 'subject','',
'email','', 'realname','',
'redirect','', 'bgcolor','',
'background','', 'link_color','',
'vlink_color','', 'text_color','',
'alink_color','', 'title','',
'sort','', 'print_config','',
'required','', 'env_report','',
'return_link_title','', 'return_link_url','',
'print_blank_fields','', 'missing_fields_redirect','',
'pgpkeyid','');

# Determine the form's REQUEST_METHOD (GET or POST) and split the form #
# fields up into their name-value pairs. If the REQUEST_METHOD was #
# not GET or POST, send an error. #
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}

# For each name-value pair: #
foreach $pair (@pairs) {

# Split the pair up into individual variables. #
local($name, $value) = split(/=/, $pair);

# Decode the form encoding on the name and value variables. #
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# If they try to include server side includes, erase them, so they
# aren't a security risk if the html gets returned. Another
# security hole plugged up.
$value =~ s/<!--(.|\n)*-->//g;

# If the field name has been specified in the %Config array, it will #
# return a 1 for defined($Config{$name}}) and we should associate #
# this value with the appropriate configuration variable. If this #
# is not a configuration form field, put it into the associative #
# array %Form, appending the value with a ', ' if there is already a #
# value present. We also save the order of the form fields in the #
# @Field_Order array so we can use this order for the generic sort. #
if (defined($Config{$name})) {
$Config{$name} = $value;
}
else {
if ($Form{$name} && $value) {
$Form{$name} = "$Form{$name}, $value";
}
elsif ($value) {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
}

 

rocknbil




msg:4261797
 6:19 pm on Feb 2, 2011 (gmt 0)

The problem will be resolved by looking here:

# Send E-Mail
&send_mail;

Look farther down in the script for

sub send_mail {
#####
}

But don't change anything, just look as described below. Even though it's an ooooold script, if it runs, it should probably work "as is." Are you sure your form data is submitting correctly?

The first place I would look is in your form, at the name of what you expect to turn up in the body. If this is a form field named "Comments" look at the send_mail sub to see what's being sent for "Comments." Remember also that $FORM{'Comments'} and $FORM{'comments'} are two different things, you probably just have a typo in the form field naming (just a guess.)

Lolley




msg:4261929
 10:43 pm on Feb 2, 2011 (gmt 0)

Thank you! I'll have a close look tomorrow. The problem has to be in the pgpformmail as the same form works on another server using a different perl script.

Will report backů

chorny




msg:4262361
 5:57 pm on Feb 3, 2011 (gmt 0)

Don't use programs from Matt's Script Archive, use replacement from nms. They are written in old-style Perl (usually version 4) and are unsecure.

Lolley




msg:4262378
 6:14 pm on Feb 3, 2011 (gmt 0)

Really? I didn't know that. The perl script was provided by the server. Sorry if this reads dumb, but what/where is nms?

Thank you.

janharders




msg:4262411
 7:27 pm on Feb 3, 2011 (gmt 0)

Since some of Matt's scripts had a few problems with security (and where out of date), a few perl programmers decided to rewrite them from scratch with security and flexibility in mind.
nms (is that "not Matt's scripts"? ;) is the name for the collection. You'll want nms formmail. Google it and you'll find the sourceforge-home.

Now, surely there are newer and more flexible solutions than nms, but they've pretty much updated Matt's great scripts: they usually run on every server that supports cgi-scripts and there's a lot of documentation and people that used them.

btw, Matt Wright himself writes
While the free code found at my web site has not evolved much in recent years, the general programming practices and standards of CGI programs have. nms is an attempt by very active programmers in the Perl community to bring the quality of code for these types of programs up to date and eliminate some of the bad programming practices and bugs found in the existing Matt's Script Archive code.

I would highly recommend downloading the nms versions if you wish to learn CGI programming. The code you find at Matt's Script Archive is not representative of how even I would code these days. My interests and activies have moved on, however, and I just have not found the time to update all of my scripts. One of the major reasons for this is that they work for many people. For this reason, I will continue to provide them to the public, but am also pleased to make you aware of well-coded alternatives.

Lolley




msg:4262661
 8:34 am on Feb 4, 2011 (gmt 0)

Thank you very much indeed, I really appreciate this!

Lolley




msg:4262898
 6:40 pm on Feb 4, 2011 (gmt 0)

The problem has been solved by using nms as described above. I especially appreciate the fact that there is no need to put an email address within the HTML!

Thanks again!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved