CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Need Script to Make

 



Revival Fire
Novice

Oct 16, 2000, 8:34 PM

Post #1 of 1 (482 views)
Need Script to Make Can't Post

I have tweaked this script somewhat but I am not great at Perl yet...Could someone tell me how to get the From field on the return formmail email to have:
1. the name
2. the return email address

I want it to be just like a normal email that I can respond to. Here is my hacked code...

#!/usr/local/bin/perl
#
############################################################################
# EZ Form Mailer Version 1.2
#
# 1.2 Corrected Y2K Compliance
#
# 1.1 Changed get_date to be Y2K compliant.
#
# Copyright 1997, 1999 3rd Coast Technologies, LLC
#
# http://www.3rdcoast.com
# support@3rdcoast.com
#
#
############################################################################
# Configuration Variables
#
# The following variables are used to define how your form data
# will be processed. The data values can be defined here in the
# script or optionally they can be sent from the form by hidden fields.
# See the readme.txt file for information on using hidden fields.
#
############################################################################
#
# $SENDMAIL identifies the location of the send mail program on
# your server. Verify this with your webmaster or isp.
# ******************************************************
# *** This variable MUST be specified here and ***
# *** cannot be sent using hidden fields. ***
# ******************************************************
#
# @AUTHURLS identifies the URL's that are authorized to use this
# CGI Script. Be sure to include all possible variations.
# ******************************************************
# *** This variable MUST be specified here and ***
# *** cannot be sent using hidden fields. ***
# ******************************************************
#
# $TO the email address where the form data will be sent.
#
# $SUBJECT the text that will be used for the subject of the email.
#
# $REDIRECT identifies the page to be displayed to the user
# after they submit the form.
#
# $SORT_TYPE defines the sort type for the form output.
# Options are 'alphabetic', 'field', or 'none'.
#
# @SORT_FIELDS If the $SORT_TYPE is 'field', enter the field names
# in the desired print sequence.
#
# When changing any of these values, be sure to include the single
# quote marks around the values and the semi colon at the end of
# each statement.
#
############################################################################
#done by
$SENDMAIL = '/usr/lib/sendmail';

@AUTHURLS = ('','');

$TO = ';

$REDIRECT = ';

$SUBJECT = '$subject';

$SORT_TYPE = 'field';

@SORT_FIELDS = ('name','address','city','state','zip','country','e-mail', 'service','comments');

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

# Check to make sure this script was called by an authorized URL(s)

&check_url;

# Reformat Form Contents

&reformat_form_data;

# Send the form data to the recipient via e-mail

&send_email;

# Redirect user to confirmation page
print "Location: $REDIRECT\n\n";
exit();

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

sub check_url
{
if ($ENV{'HTTP_REFERER'})
{
foreach $AUTHURL (@AUTHURLS)
{
if ($ENV{'HTTP_REFERER'} =~ /$AUTHURL/i)
{
$check_url = '1';
last;
}
}
}
else
{
$check_url = '1';
}

if ($check_url != 1)
{
print "Content-type: text/html\n\n";
print "<html>\n <head>\n <title>Unauthorized URL Referrer - Access Denied</title>\n </head>\n";
print " <body>\n <center>\n <h1>Unauthorized URL Referrer - Access Denied</h1>\n </center>\n";
print "The form that is trying to use this script resides at: \n";
print "$ENV{'HTTP_REFERER'}, which is not allowed to access this cgi script.<p>\n";
print "Sorry!\n";
print "</body></html>\n";
exit;
}

}

sub reformat_form_data
{
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else
{
print "Content-type: text/html\n\n";
print "<html>\n <head>\n <title>Error: Request Method</title>\n </head>\n";
print "<body>\n <center>\n\n <h1>Error: Request Method</h1>\n </center>\n\n";
print "The Request Method of the Form you submitted was not\n";
print "POST. Please check the form, and make sure the\n";
print "method= statement is in upper case and is set to POST.\n";
print "<p><hr size=7 width=75%><p>\n";
print "<ul>\n";
print "<li><a href=\"$ENV{'HTTP_REFERER'}\">Back to the Submission Form</a>\n";
print "</ul>\n";
print "</body></html>\n";
exit;
}
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$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;
$value =~ s/<!--(.|\n)*-->//g;
if ($name eq 'to_email' && ($value))
{
# don't allow spammers to send mail to anybody
# $TO = $value;
}
elsif ($name eq 'subject' && ($value))
{
$SUBJECT = $value;
}
elsif ($name eq 'redirect' && ($value))
{
# don't redirect to some other place
# $REDIRECT = $value;
}
elsif ($name eq 'sort_type' && ($value))
{
# don't sort by anything else
# $SORT_TYPE = $value;
}
elsif ($name eq 'sort_fields' && ($value))
{
# don't change the sort fields
# @SORT_FIELDS = split(/,/, $value);
}
elsif ($FORM{$name} && ($value))
{
$FORM{$name} = "$FORM{$name}, $value";
}
elsif ($value)
{
$FORM{$name} = $value;
}
}
}

sub send_email
{
# Build the 'from' address of the form: "name <email address>"
open(MAIL,"|$SENDMAIL -t") &#0124; &#0124; die "Can't open $mailprog!\n";

# Output the mail header

print MAIL "To: $TO\r\n";
print MAIL "From: $FORM{'email'} ($FORM{'name'})\r\n";
print MAIL "Reply-To: $FORM{'email'} ($FORM{'name'})\r\n";
print MAIL "Subject: $SUBJECT\r\n\n";

# Output the mail body
# Optionally Sort and Print the name and value pairs in FORM array

if ($SORT_TYPE eq 'alphabetic')
{
foreach $key (sort keys %FORM)
{
print MAIL "$key: $FORM{$key}\n\n";
}
}

elsif ($SORT_TYPE eq 'field')
{
foreach $SORT_FIELD (@SORT_FIELDS)
{
if ($FORM{$SORT_FIELD})
{
print MAIL "$SORT_FIELD: $FORM{$SORT_FIELD}$key\n";
delete $FORM{$SORT_FIELD}; # remove it from the hash
}
}
# print what's left
foreach $key (keys %FORM)
{
print MAIL "$key: $FORM{$key}\n";
}
}
else
{
foreach $key (keys %FORM)
{
print MAIL "$key: $FORM{$key}\n\n";
}
}

# Close the pipe and send the mail

close(MAIL);
}
# now print something to the HTML page, usually thanking
# the person for filling out the form, and giving them a
# link back to your homepage

print <<EndHTML;
<h2>Thank You!</h2>
$Form($name), we really appreciate you taking the time to contacting <p>God Bless You<p>
Return to our <a href="index.html">home page</a>.
</body></html>
EndHTML



------------------
John 3:16


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives