html course, website building, perl scripting, mysql databases, web site builder, build a website

  

 



Testimonial

Hey Dave:

You are brilliant! I was skeptical when I reviewed Instant Site Maker. I mean, I am a professional Webmaster after all. The first thing I noticed was the simplicity of your tool. Just plug in the info and walla, a gorgeous web page. I'll be using this on my next mini-site project. Thanks for bringing Instant Site Maker to market. You've made my life easier and probably for thousands of others!

Jim Mandich, Storm Golf

simple email form



Below is a simple html email form and associated Perl script used to process the information. Please feel free to use the code, but note - the code has been modified to display on the page rather than execute in the browser.

Please also note we can't provide support so don't email asking for help to get it working - you're getting it free aren't you? :-)

This simple form has no field vaidation or error checking. There is a brief description of how the form works at the bottom of the page. The example here works on UNIX, Linux servers etc. It is not designed for Windows servers.

Html Email Form Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<form action="cgi-bin/email_process.cgi" method="post">
<table border="0">
<TR>
<TD COLSPAN="2">Please fill in the details below to send us a message</TD>
</TR>
<TR>
<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
<TD align="left" width="20%"><B>Name:</B></TD>
<TD><input type="text" name="fname"></TD>
</TR>
<TR>
<TD align="left" width="20%"><b>Email Address:</b></TD>
<TD><input type="text" name="email_add"></TD>
</TR>
<TR><TD ALIGN=left valign="top" width="20%"><b>Message:</b></TD>
<TD><textarea name="email_msg" rows="20" cols="30"></textarea></TD>
</TR>
<TR>
<TD colspan="2">&nbsp;</TD></TR>
<TR><TD colspan="2"><center><INPUT TYPE="submit" VALUE="Send Message"></center></TD>
</TR>
</TABLE>
</form>
</BODY>
</HTML>

Associated Perl Script:

#!/usr/bin/perl

use strict;

use CGI;

my $cgiobject = new CGI;

my $fname=$cgiobject->param("fname");
my $email_add=$cgiobject->param("email_add");
my $email_msg=$cgiobject->param("email_msg");

print "Content-type: text/html\n\n";
 
open (MAIL, "|/usr/lib/sendmail your.name\@yourdomain.com") || &errormess;
 print MAIL "From: $email_add\n";
 print MAIL "Reply-to: $email_add\n";
 print MAIL "Subject: Email From Your Website\n";
 print MAIL "Name $fname\n";
 print MAIL "email $email_add\n";
 print MAIL "Msg $email_msg\n";
close(MAIL);

 

print <<"html";
<HTML>
<HEAD>
<TITLE> Contact Us </TITLE>
</HEAD>
<BODY >
<H4>Thank you - your message has been sent. You will be contacted shortly.
</BODY>
</HTML>
html

exit;

 sub errormess {
   print "<BR>Problem sending mail Aborting\n";
  exit;  
}

Brief Overview:

The email form takes in 3 parameters, Name, Email and Message:
<input type="text" name="fname">
<input type="text" name="email_add">
<textarea name="email_msg" rows="20" cols="30"></textarea>

These values are picked up by the Perl script via a cgi object and assigned to 3 variables:

my $fname=$cgiobject->param("fname");
my $email_add=$cgiobject->param("email_add");
my $email_msg=$cgiobject->param("email_msg");

Notice that the name in bold must be the same in both the html form and Perl script.

The script then send the mesasge out:
open (MAIL, "|/usr/lib/sendmail your.name\@yourdomain.com") || &errormess;

/usr/lib/sendmail is the path to your sendmail program (your web host can give you this information) and the email address used (your.name\@yourdomain.com in this example) MUST have a backslash before the @ sign as this is a special character in Perl.

Finally the script displays a mesasge back to the browser:

print <<"html_msg";
<HTML>
<HEAD>
<TITLE> Contact Us </TITLE>
</HEAD>
<BODY >
<H4>Thank you - your message has been sent. You will be contacted shortly.
</BODY>
</HTML>
html_msg

Please note the 'html_msg' tag on the last line must start in column one or the script will fail.

 




Main Menu

web site tools
build a website blog
html help
html redirect
html marquee
html form
instant site maker
simple style sheet
is your site on life support
internet marketing
meta tags
perl cgi
javascript
javascript display date
email filters
simple email form
protect your code
disable right mouse
help visitors bookmark your site
free hosting vs paid
accept credit card payments
card payments using clickbank
newsletter
sep 29 newsletter
oct 10 newsletter
oct 24 newsletter
what is bandwidth
how much web space
contact us
resources
link to us
Links Directory

 

 

© All rights Reserved. No part of this site may be reproduced or copied without permission of the owners.
Site Directory