Web site promotion
Main Search Engines and Directories

 

Free URL Monitoring
Now with SMS Text alerts!!

Yahoo Slurp?

Optimise for Yahoo

PageRank Explained

MSN launch Google Rival

 


 

 

Forms - Form to Email script

Example form to email cgi script for a Unix Hosting plan up to Windows 2003 servers.

Simply copy the jmail.pl below into your cgi-bin folder. Save as jmail.pl (you can use notepad for this)

Insert the form method <form method="POST" action="cgi-bin/jmail.pl"> into your form.

Only two hidden fields are required:-

<input type="hidden" name="subject" value="Your Website Booking Form">
<input type="hidden" name="recipient" value="you@yourdomain.co.uk">

Ensure the email field is labeled email not E-mail or anything else. This means the email address of the sender appears as where the form was sent from. Meaning clicking reply when you receive the form emails it back to the person that filled it out.

You can have as many text fields drop downs etc as you wish, the only critical is email must be labeled email.

The form is sent marked high priority.

The form fields appear as in the original form.

Create a thank you or confirmation page and name it thanks.html

That's it. Simple. Copy and paste the script below:


use OLE;
use CGI;
$jmail = CreateObject OLE "JMail.SMTPMail";
print "Content-type: text/html\n\n";
$form = new CGI;

$domain = $ENV {'SERVER_NAME'};
$referer = $ENV {'HTTP_REFERER'};
$url = $referer;
$url =~ s/^http:\/\///i;
$url =~ s/^www\.//i;
$domain =~ s/^www\.//i;

$Sender = $form->param('email');

$SMTPServer = "smtp.$domain:25";
#$Recipient = "form\@$SMTPServer";
$Recipient = $form->param('recipient');
$Subject = $form->param('subject');
$Priority=1;
$Header = "Originating-IP", $ENV{'REMOTE_ADDR'};

$jmail->{ServerAddress} = $SMTPServer;
$jmail->{Sender} = $Sender;
$jmail->{Subject} = $Subject;
$jmail->AddRecipient ($Recipient);

$mail_body = '';

foreach $field ($form->param) {
foreach $value ($form->param($field)) {
$mail_body .= "$field: $value\n";
}
}

$jmail->{Body} = $mail_body;
$jmail->{Priority} = $Priority;
$jmail->AddHeader ($Header);

if ($url =~ m/^$domain/)
{
$mailmessage = "Mail was sent.";
$jmail->Execute;
}
else
{
$mailmessage = "mail not sent. Incorrect Referer";
}

print "Content-type: text\n\n";
print "Result: $mailmessage\n\n";
#print "Recipient: $Recipient\n\t\n";
#print "Sender: $Sender SMTP Server: $SMTPServer\t";
#print "Subject: $Subject Referer: $referer";
#print "Domain: $domain url: $url ";


print <<"(END ERROR HTML)";

Content-type: text/html

<html>
<head>
<title>Enquiry</title>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=../thanks.html">
</head>
<body>

</body>
</html>
(END ERROR HTML)


Comments:

I am afraid we do not offer free support for forms unless you are already a customer of ours.

If this has helped you please link to us :
Link to us like this:
< a href=" http://www.beyonder.co.uk/ form_to_email_script.htm " target="_blank">form to email script</a>

October 29, 2003

 

 

 

 

 

 

 

 


©1998-2007 Beyonder SEO. Internet marketing UK
Tel: + 44 (0)20 7 193 6001 E-mail: SalesDept @ beyonder.co.uk
  SITEMAP · CONTACT · HOME