Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formmail Thank You page style 2

Status
Not open for further replies.

dmacster

Technical User
Jan 28, 2005
670
US
Using the nms formmail version - is there an easy way to improve the look of the Thank You page that lists what the user has submitted?

Thanks,
Donna
 
Hi Donna,

I have an exclenent FormMail script that i use, coded in CGI. it posts the user to whatever page you want after completion, it then sends them a confirmation e-mail including the details they entered.

If that sounds like somthing that might interest you let me know.

Rob
 
Thanks - I was actually trying to redo to use TFmail from nms - but now I'm getting premature end of script headers errors. Super confused!
 
Oh, I just figured out my own stupidity with the premature end error - forgot to set the permissions of the script.
 
TamedTech,
I would be interested in that script :)
 
Sure thing my man,

I'll post it up in the morning for you once i'm back in the office with a list of instructions to use it.

Rob
 
OK, so if you havn't worked with Perl or CGI before this may look a little intimidating, it really isnt. The process will consist of four files, firstly an HTML file which contains a <form> which will post the input information to your contact.cgi script, you will have a thanks.htm if things are processed ok and a fail.htm if things go wrong.

The Contact Form -

This is a code snipit of the form that will post to your script, at the moment the script is limited to only 5 fields; name, company name, telephone, e-mail, message... this should be enough for simple contact, once you are used to using the script you will be able to ammend it. so, put the following code in your contact.htm or whatever code you might be using.

Code:
<form action="[b]Destination for CGI script goes here[/b]" method="POST">
<table width="98%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="25%">Name</td>
<td width="50%">&nbsp;<input name="name" type="text" size="65">
</td>
</tr>
<tr>
<td width="25%">Company Name</td>
<td width="50%">&nbsp;<input name="cname" type="text" size="65">
</td>
</tr>
<tr>
<td width="25%">Telephone</td>
<td width="50%">&nbsp;<input name="tel" type="text" size="65">
</td>
</tr>
<tr>
<td width="25%">E-mail</td>
<td width="50%">&nbsp;<input name="email" type="text" size="65">
</td>
</tr>
<tr>
<td width="25%">Message</td>
<td width="50%">&nbsp;<textarea name="dep" cols="50" rows="10">Type Your Message Here ...</textarea>
</td>
</tr>
<tr>
<td width="25%" height="30"> <div align="right"> <font size="2">
<input type="submit" value="Click to Send" name="B1">
</font></div></td>
<td width="50%" height="30"> <font size="2">
<input type="reset" value="Reset" name="B2">
</font></td>
</tr>
</table>
</form>

That should do you for a basic contact form, provided you keep the input names the same you wont have any beef.

The CGI Script

This is the tricky bit, you'll need to open a plain text editor and copy this code into it and save it with the extension ".cgi", this can then be placed usualy in your cgi-bin on you hosting account.

Ammend all the details you need to in this code, starting with the top section, change all the URL's to match those of your site.

Then slightly further down you will find the message text for the e-mail to yourselevs and the auto-reply that is posted to the user of the site after thier enquiry.

You shouldnt need to make any other changes as the rest of the script is just processing a few checks such as the require fiels and that the e-mail address supplied is in the correct format.

Once you have made these changes up-load the file into your cgi-bin and you will need to change the CCHMOD setting to 775, the process for doing this will change on your FTP program, try right clicking the file and having a look at what options it gives you. If you need help then dont hesistate to ask.

Code:
#!/usr/bin/perl --


# URL to go to if there is a problem with form input
$ErrorPage = "http://[b]your domain[/b]/fail.htm";

# URL to go to when form has been successfully submitted
$ThankPage = "http:/[b]your domain[/b]/thanks.htm";

# URL to go to if a 'foreign' referer calls the script
$EvilReferer = "http://[b]your domain[/b]/index.htm";

# E-mail address to send intake form to (your address)
# If not using PERL 5, escape the @ thus: \@ instead of @ 
$YourEmail = '[b]your e-mail address[/b]';

# Script works only on your server(s) - ('URL1','URL2')
@referers = ('http://[b]your domain[/b]/',);

# Location of mail program - check your doc or ask admin
$MailProgram = '/usr/sbin/sendmail -i -t';

# Subject of the e-mail autoreply to the submitter
$Subject = "[b]your company name[/b] Message Received on ";

##### END OF SETTABLE VARIABLES ############################



##### MAIN PROGRAM #########################################
# ___ Do not edit below this line __________________________

&CheckReferingURL;
&ReadParse;
$name = $in{'name'};
$cname = $in{'cname'};
$tel = $in{'tel'};
$dep = $in{'dep'};
$email = $in{'email'};
&CheckEmailAddressFormat;
&CheckFields;
&GetDate;
&SendSubmission;
&SendAutoReply;
print "Location: $ThankPage\n\n";
exit;

# _________________________________________________________

sub SendSubmission {
open (MAIL,"|$MailProgram -t");
print MAIL "To: $email\n";
print MAIL "From: $YourEmail\n";
print MAIL "Subject: $Subject $Date, $Timesent\n";
print MAIL "Dear $name,\n\n";
print MAIL "Thanks for your enquiry, we will respond as soon as possible. \n\n";
print MAIL "Kind Regards\n\n";
print MAIL "[b]your domain[/b]\n";
print MAIL "[b]your company name[/b]\n\n";
print MAIL "Tel: [b]telephone[/b]\n";
print MAIL "Fax: [b]fax[/b] \n";
print MAIL "Email: sales\@[b]your domain[/b] \n";
print MAIL "Website: [b]your domain[/b] \n\n";
print MAIL "-------------------------------------------------------------\n";
print MAIL "COPY OF INTERNET RESPONSE FORM\n\n";
print MAIL "Name: $name\n";
print MAIL "Company: $cname\n";
print MAIL "Telephone: $tel\n";
print MAIL "Interest: $dep\n";
print MAIL "Email: $email\n\n";
print MAIL "****************************************************************************\n";
print MAIL "CONFIDENTIALITY NOTICE\n";
print MAIL "This Email and any files transmitted with it are confidential and may be\n";
print MAIL "privileged.  They are intended solely for the use of the individual or\n";
print MAIL "entity to which they are addressed. If you have received this Email in\n";
print MAIL "error you should not copy or use it for any purpose or disclose its contents\n";
print MAIL "to any person.  You should deliver the message to the intended addressee. \n";
print MAIL "Unauthorised use or disclosure is prohibited and may be unlawful.\n";
print MAIL "****************************************************************************\n";
close (MAIL);
}

# _________________________________________________________

sub SendAutoReply {
open (MAIL,"|$MailProgram -t");
print MAIL "To: $YourEmail\n";
print MAIL "From: $email\n";
print MAIL "Subject: Customer enquiry from [b]your domain[/b]\n";
print MAIL "To [b]your company name[/b],\n\n";
print MAIL "$name has used the website on $Date, $Timesent, and has input the following information\n\n";
print MAIL "We have agreed to reply to the enquiry as soon as possible\n\n";
print MAIL "-------------------------------------------------------------\n";
print MAIL "Name: $name\n";
print MAIL "Company: $cname\n";
print MAIL "Telephone: $tel\n";
print MAIL "Interest: $dep\n";
print MAIL "Email: $email\n\n";
print MAIL "****************************************************************************\n";
print MAIL "CONFIDENTIALITY NOTICE\n";
print MAIL "This Email and any files transmitted with it are confidential and may be\n";
print MAIL "privileged.  They are intended solely for the use of the individual or\n";
print MAIL "entity to which they are addressed. If you have received this Email in\n";
print MAIL "error you should not copy or use it for any purpose or disclose its contents\n";
print MAIL "to any person.  You should deliver the message to the intended addressee. \n";
print MAIL "Unauthorised use or disclosure is prohibited and may be unlawful.\n";
print MAIL "****************************************************************************\n";
close (MAIL);
}

# _________________________________________________________

sub GetDate {
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('01','02','03','04','05','06','07','08','09','10','11','12');
@minutes = ('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17',
'18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34',
'35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51',
'52','53','54','55','56','57','58','59');
@seconds = ('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17',
'18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34',
'35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51',
'52','53','54','55','56','57','58','59');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year+1900;
$Date = "$days[$wday] $mday/$months[$mon]/$year";
$Timesent = "$hour:$minutes[$min]:$seconds[$sec]";
}

# _________________________________________________________

sub ReadParse { local (*in) = @_ if @_; 
local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" ) 
{$in = $ENV{'QUERY_STRING'};} 
elsif ($ENV{'REQUEST_METHOD'} eq "POST") 
{read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} 
else { 
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g; } @in = split(/&/,$in);
foreach $i (0 .. $#in) { 
$in[$i] =~ s/\+/ /g; 
($key, $val) = split(/=/,$in[$i],2); 
$key =~ s/%(..)/pack("c",hex($1))/ge; 
$val =~ s/%(..)/pack("c",hex($1))/ge; 
$in{$key} .= "\0" if (defined($in{$key})); 
$in{$key} .= $val; } return length($in); }

# _________________________________________________________

sub CheckEmailAddressFormat {
if (index($email, "@") < 1)  {&DoEmailError;}
if (index($email, ".") < 1)  {&DoEmailError;}
if (index($email, " ") > -1) {&DoEmailError;}
}
sub CheckFields {
if (!$cname || $cname eq ' ') {&DoEmailError;}
if (!$name || $name eq ' ') {&DoEmailError;}
if (!$email || $email eq ' ') {&DoEmailError;}
if (!$tel || $tel eq ' ') {&DoEmailError;}
}
sub DoEmailError {
print "Location: $ErrorPage\n\n";
exit;
}

# _________________________________________________________

sub CheckReferingURL {
if ($ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ /$referer/i) {
$check_referer = '1';
last;
}}}
else {$check_referer = '1';}
if ($check_referer != 1) {
print "Location: $EvilReferer\n\n";
exit;
}}

# _________________________________________________________

exit;

##### End of Script ########################################

And that my friend should be bob's your job, i'm not that happy about posting all the code snippets on the forum like that but it would seem Board rules dont permit we release e-mail address's so putting a copy over e-mail isnt an option.

If you have any questions then feel free to ask, i'm hoping that script is bug free, provided you only change the sections highlighted in bold then you should be fine.

You may have to change the path to SendMail aswell ... its all dependant on your ISP.

Although it looks daunting, its suprisingly simple code once you get used to reading it.

Kind Regards,

Rob
 
Rob

Might be worth posting it as a faq for others?

Cheech

[Peace][Pipe]
 
Nice Idea Cheech ... i'll get round t writing it all up properly later on, maybe go into a little more depth about the CGI Script and how to make additions to it, then post it as a FAQ.

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top