Important alert: (current site time 4/19/2014 2:36:22 AM EDT)
 

VB icon

CGI Form-Mailer

Email
Submitted on: 1/2/2002 5:27:40 PM
By: Verite Donato  
Level: Advanced
User Rating: By 1 Users
Compatibility: 5.0 (all versions), Active Perl specific, 4.0 (all versions), 3.0 (all versions), Pre 3.0
Views: 16296
author picture
(About the author)
 
     This simple CGI script allows a webmaster to give his visitors a way to e-mail him from an HTML form. It utilizes the server's mail transport agent ( such as SENDMAIL ) and is fully customizable. That is, you can modify all parameters right from the HTML form itself! This should be good news for those who are not CGI programmers.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: CGI Form-Mailer
= Description:This simple CGI script allows a webmaster to give his visitors a way to e-mail him from an HTML form. It utilizes the server's mail transport agent ( such as SENDMAIL ) and is fully customizable. That is, you can modify all parameters right from the HTML form itself! This should be good news for those who are not CGI programmers.
= By: Verite Donato
=
= Inputs:All parameters must be changed from within the HTML document containing the form. An explanation follows:
"redir" is a hidden field that specifies where the script should redirect the user after the message has been sent.
"showFields" is a hidden field that specifies whether the script should print the HTML form fields along with the corresponding values.
"to" should probably be hidden, but does not have to be. You should put here the e-mail address of the person to which the message should be sent.
"from" is simply the e-mail address of the person from whom the message is sent.
"subject" is a short string of text that specifies what the message is about.
After "subject", you can put as many form fields as you want. They will simply become the body of the e-mail message.
=
= Returns:The user will be redirected to the page specified in the "redir" form field.
=
= Assumes:The only possible modification you might have to make is with the $mailerPath scalar variable. If
your server doesn't use sendmail, you will need to change the contents of that variable to whatever mail agent your server does use.
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=267&lngWId=6=for details.=**************************************

#!/usr/local/bin/perl
$mailerPath = "/usr/sbin/sendmail -t";
print "Content-type: text/html\n\n";
$queryString = <STDIN>;
@elements = split ( '&', $queryString );
$idx = 0;
foreach $item ( @elements ) {
($field, $value) = split ( '=', $item );
$fields[$idx] = $field;
$values[$idx] = $value;
$values[$idx] =~ s/\+/ /g;
$values[$idx] =~ s/%([a-fA-F0-9][a-dA-F0-9])/pack("C",hex($1))/eg;
$idx++;
}
my $redir = $values[0];
my $showFields = $values[1];
open ( MAILPIPE, "|$mailerPath" ) or die "Error opening $mailerPath: $!\n\n";
print MAILPIPE "To: $values[2]\nFrom: $values[3]\n";
print MAILPIPE "Subject: $values[4]\n\n";
for ( $i = 3; $i < $idx; $i++ ) {
 if ( $showFields ) {
 print MAILPIPE "$fields[$i] : $values[$i]\n";
 }
 else {
	print MAILPIPE "$values[$i]\n";
 }
}
close ( MAILPIPE );
print "<SCRIPT>location='$redir';</SCRIPT>";


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.