View Full Version : Email form help?
sjohnson
03-20-2006, 08:34 PM
I have an email form on my webpage that I want people to fill out in regards to any information. When I click Submit with the code that I have, it starts to open outlook express. How can I Submit the email using CGI and bypassing Outlook Express. Here's my code ....Please Help! Are there any free CGI scripts I can find out there??
<form action="mailto:justtermed@aol.com" subject="Termite Control" method="post" enctype="text/plain">
<table id="table2">
<tbody>
<tr>
<th scope="row"><font color="red">*</font>Name:</th>
<td><INPUT TYPE="text" NAME="inputbox" size="30"></td>
</tr>
<tr class="odd">
<th scope="row">Address:</th>
<td><INPUT TYPE="text" NAME="inputbox2" size="30"></td>
</tr>
<tr>
<th scope="row">City:</th>
<td><INPUT TYPE="text" NAME="inputbox3" size="30"></td>
</tr>
<tr>
<th scope="row">Zip:</th>
<td><INPUT TYPE="text" NAME="inputbox4" size="30"></td>
</tr>
<tr>
<th scope="row"><font color="red">*</font>Phone Number:</th>
<td><INPUT TYPE="text" NAME="inputbox5" size="30"></td>
</tr>
<tr>
<th scope="row">Business/Residence:</th>
<td><INPUT TYPE="text" NAME="inputbox6" size="30"></td>
</tr>
<tr>
<th scope="row" valign="top"><font color="red">*</font>Comments/Questions:</th>
<td>
<TEXTAREA name="comment" cols="25" wrap="virtual" rows="10">
</TEXTAREA>
</td>
</tr>
<tr>
<th scope="row"></th>
<td>
<INPUT type="submit" name="submit" value="Submit" class="button">
<INPUT type="reset" name="reset" value="Reset" class="button">
</td>
</tr>
</tbody>
</table>
FishMonger
03-20-2006, 08:52 PM
You need to set the action to point to your cgi script.
change:
action="mailto:justtermed@aol.com"
to this (path needs to be adjusted to fit your server requirments).
action="cgi-bin/myscript.pl"
Here's a link to one of the best formmail scripts.
http://nms-cgi.sourceforge.net/scripts.shtml
sjohnson
03-21-2006, 12:47 AM
I'm trying to get this form working, but It's been a pain. I went to that site, but theres only one that i saw that could have helped me and that was a file called 'tfmail'. Can anyone help??
Calilo
03-21-2006, 01:36 AM
What you need as FishMonger said, it your form, to send the data to a CGI script which will then, send you the information, to the e-mail addres you specify, but you need a host that supports cgi/perl execution and thas has got sendmail. if you do have that, then you need the cgi to proces the info, you can use this one.
just save it, then upload it in ascii mode and chmod 755 it, (in unix) then youll have to setup the form as fishmonger said, to direct to the cgi script, (action="script.cgi")
good luck
#!/usr/bin/perl
###
##
# This script was creted by
# Calilo
# Any questions or sugestions warmly received
##
###
###
##
$sendmail = '/usr/sbin/sendmail -t'; # Where is sendmail?
$to = 'myname@mymail.com'; # Who is going to receive the mail.
$from = 'My Mail sender'; # From who the mail is sended.
$subject = 'Mail'; # The Mail's Subject.
$location = 'http://www.mydomain.net/after.html'; # The page to be redirect after the mail was sended.
##
###
###
##
read(STDIN, $namevalues, $ENV{'CONTENT_LENGTH'});
open (MAIL, "|$sendmail") || die "Can't open $sendmail!\n";
print MAIL ("To: $to\n");
print MAIL ("From: $from\n");
print MAIL ("Subject: $subject\n\n");
# Process info from Fill in Form
@namevalues = split(/&/, $namevalues);
foreach $namevalue (@namevalues) {
($name, $value) = split(/=/, $namevalue);
$name =~ tr/+/ /;
$value =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$INPUT{$name} = $value;
unless ($value eq "") {
print MAIL ("$name: $value\n");
}
}
close (MAIL);
print ("Location: $location\n\n");
exit;
##
###
Calillo :thumbsup:
FishMonger
03-21-2006, 08:00 AM
Calillo,
Is there a particular reason why you're using that method for reading/parsing the form submission? Doing the parsing directly in the script like that has been depreciated for 10+ years. The de facto standard is to use the CGI module. Perl cgi scripts that use that method instead of the cgi module are frowned upon.
Sjohnson,
There are 2 scripts on that site that will do what you need, TFMail and FormMail. TFMail is newer scaled down implementation of FormMail. Both of which are more than what you need but include far more security and error handling than we will provide.
Here's a script that sends the email of the form submission and then redirects to another page. You'll need to adjust the paths to match you server setup. I also changed the names of your form fields to be more descriptive. The script has a minimum level of error handling, but it should be enough to get you started.
If you have any problems, post the exact error message.
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
my $q = new CGI;
my %form = $q->Vars;
my $to = 'me@mydomain.com';
my $from = 'me@mydomain.com';
my $subject = 'form submission';
open (MAIL, '|/usr/sbin/sendmail -t') || die "Can't pipe to sendmail!\n";
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$_: $form{$_}\n" foreach (keys %form);
close MAIL;
print $q->redirect("http://www.mydomain.net/after.html");
<form action="../cgi-bin/mailform.pl" method="post">
<table id="table2">
<tbody>
<tr>
<th scope="row"><font color="red">*</font>Name:</th>
<td><INPUT TYPE="text" NAME="Name" size="30"></td>
</tr>
<tr class="odd">
<th scope="row">Address:</th>
<td><INPUT TYPE="text" NAME="Address" size="30"></td>
</tr>
<tr>
<th scope="row">City:</th>
<td><INPUT TYPE="text" NAME="City" size="30"></td>
</tr>
<tr>
<th scope="row">State:</th>
<td><INPUT TYPE="text" NAME="State" size="30"></td>
</tr>
<tr>
<th scope="row">Zip:</th>
<td><INPUT TYPE="text" NAME="Zip" size="30"></td>
</tr>
<tr>
<th scope="row"><font color="red">*</font>Phone Number:</th>
<td><INPUT TYPE="text" NAME="Phone" size="30"></td>
</tr>
<tr>
<th scope="row">Business/Residence:</th>
<td><INPUT TYPE="text" NAME="Bus/Res" size="30"></td>
</tr>
<tr>
<th scope="row" valign="top"><font color="red">*</font>Comments/Questions:</th>
<td>
<TEXTAREA name="comment" cols="25" wrap="virtual" rows="10">
</TEXTAREA>
</td>
</tr>
<tr>
<th scope="row"></th>
<td>
<INPUT type="submit" name="submit" value="Submit" class="button">
<INPUT type="reset" name="reset" value="Reset" class="button">
</td>
</tr>
</tbody>
</table>
</form>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.