Bu örneğin iki bölümü mevcuttur. Cgi
ve swf dosyası.
Cgi dosyası: Altaki kodları
kopyalayıp bir text dosyasına yapıştırın. Kırmızı
alanları kendinize uygun olanla değiştirin. Metni kopyalayın ve
bir txt dosyasına yapıştırın. Dosyanın adını ezformml.cgi
olarak değiştirin.
#!/usr/local/bin/perl
#
############################################################################
# EZ Form Mailer Version 1.1
#
# 1.1 Changed get_date to be Y2K compliant.
#
# Copyright 1997, 1999 3rd Coast Technologies, LLC
#
# http://www.3rdcoast.com
# support@3rdcoast.com
#
# This CGI script takes the data entered in an HTML form
# and sends it via e-mail to the specified location.
#
# EZ Form Mailer is available for anyone to use or modify for
no charge.
# All we ask is that you leave this copyright notice in the script
# and readme.txt file. If someone asks where you got the script,
# refer them to 3rd Coast Technologies.
#
# Selling or distributing this program without prior written approval
# is forbidden.
#
############################################################################
# Configuration Variables
#
# The following variables are used to define how your form data
# will be processed. The data values can be defined here in the
# script or optionally they can be sent from the form by hidden
fields.
#
############################################################################
#
# $SENDMAIL identifies the location of the send mail program on
# your server. Verify this with your webmaster or isp.
# ******************************************************
# *** This variable MUST be specified here and ***
# *** cannot be sent using hidden fields. ***
# ******************************************************
#
# @AUTHURLS identifies the URL's that are authorized to use this
# CGI Script. Be sure to include all possible variations.
# ******************************************************
# *** This variable MUST be specified here and ***
# *** cannot be sent using hidden fields. ***
# ******************************************************
#
# $TO the email address where the form data will be sent.
#
# $SUBJECT the text that will be used for the subject of the email.
#
# $SORT_TYPE defines the sort type for the form output.
# Options are 'alphabetic', 'field', or 'none'.
#
# @SORT_FIELDS If the $SORT_TYPE is 'field', enter the field names
# in the desired print sequence.
#
# When changing any of these values, be sure to include the single
# quote marks around the values and the semi colon at the end
of
# each statement.
#
############################################################################
sub check_url
{
if ($ENV{'HTTP_REFERER'})
{
foreach $AUTHURL (@AUTHURLS)
{
if ($ENV{'HTTP_REFERER'} =~ /$AUTHURL/i)
{
$check_url = '1';
last;
}
}
}
else
{
$check_url = '1';
}
if ($check_url != 1)
{
print "Content-type: text/html\n\n";
print "<html>\n <head>\n <title>Unauthorized
URL Referrer - Access Denied</title>\n </head>\n";
print " <body>\n <center>\n <h1>Unauthorized
URL Referrer - Access Denied</h1>\n </center>\n";
print "The form that is trying to use this script resides
at: \n";
print "$ENV{'HTTP_REFERER'}, which is not allowed to access
this cgi script.<p>\n";
print "Sorry!\n";
print "</body></html>\n";
exit;
}
}
sub reformat_form_data
{
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else
{
print "Content-type: text/html\n\n";
print "<html>\n <head>\n <title>Error:
Request Method</title>\n </head>\n";
print "<body>\n <center>\n\n <h1>Error:
Request Method</h1>\n </center>\n\n";
print "The Request Method of the Form you submitted was not\n";
print "POST. Please check the form, and make sure the\n";
print "method= statement is in upper case and is set to POST.\n";
print "<p><hr size=7 width=75%><p>\n";
print "<ul>\n";
print "<li><a href=\"$ENV{'HTTP_REFERER'}\">Back
to the Submission Form</a>\n";
print "</ul>\n";
print "</body></html>\n";
exit;
}
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($name eq 'email' || $name eq 'Name' && ($value))
{
$CONFIG{$name} = $value;
}
if ($name eq 'to_email' && ($value))
{
$TO = $value;
}
elsif ($name eq 'subject' && ($value))
{
$SUBJECT = $value;
}
elsif ($name eq 'redirect' && ($value))
{
$REDIRECT = $value;
}
elsif ($name eq 'sort_type' && ($value))
{
$SORT_TYPE = $value;
}
elsif ($name eq 'sort_fields' && ($value))
{
@SORT_FIELDS = split(/,/, $value);
}
elsif ($FORM{$name} && ($value))
{
$FORM{$name} = "$FORM{$name}, $value";
}
elsif ($value)
{
$FORM{$name} = $value;
}
}
}
sub send_email
{
# Build the 'from' address of the form: "name <email address>"
open(MAIL,"|$SENDMAIL
-t") || die "Can't open $mailprog!\n";
# Output the mail header
print MAIL "To: $TO\r\n";
print MAIL "From: $from_name\r\n";
print MAIL "Reply-To: $from_name\r\n";
print MAIL "Subject: $SUBJECT\r\n\n";
# Output the mail body
# Optionally Sort and Print the name and value pairs in FORM array
if ($SORT_TYPE eq 'alphabetic')
{
foreach $key (sort keys %FORM)
{
print MAIL "$key: $FORM{$key}\n\n";
}
}
elsif ($SORT_TYPE eq 'field')
{
foreach $SORT_FIELD (@SORT_FIELDS)
{
if ($FORM{$SORT_FIELD})
{
print MAIL "$SORT_FIELD: $FORM{$SORT_FIELD}\n\n";
}
}
}
else
{
foreach $key (keys %FORM)
{
print MAIL "$key: $FORM{$key}\n\n";
}
}
# Close the pipe and send the mail
close(MAIL);
}
Swf dosyası: Fla dosyasını incelediğinizde
3 scene bulunduğunu göreceksiniz.
Scene.Form:
Sahnenin renk ve görüntüsünü başka şekilde ayarlayabilirsiniz.
Bu scenede name, mail ve comments
adı verilen 3 input text alanı mevcuttur. Comments alanını multiline
ayarlayın. Diğer alanlar single line şeklinde kalsın.
Gönder ve sil
adında iki buton mevcuttur. Gönder butonuna şu
kodları yazın. Açıklamalar kodlarda mev cuttur:
on (release, keyPress "<Enter>")
{
// Gerekli alanların doldurulmuş olduğu denetleniyor
if (name ne "" and email ne "" and comments
ne "") {
// E-mail adresinin içeriği ve @ işareti varlığı kontrol ediliyor.
i = "0";
validmail = 0;
while (Number(i)<=Number(length(email))) {
if (substring(email,i, 1) eq "@") {
validmail = 1;
}
i = Number(i)+1;
}
// @ yoksa hata sahnesine gönderiliyor.
if (Number(validmail) == 0) {
gotoAndStop ("Scene: Hata", 1);
} else {
// Aşağıdaki cgi dosyasının html dosyası ile aynı directorde olması
gereklidir.
loadVariablesNum ("ezformml.cgi", 0, "POST");
// Bilgi sahnesine gönderiliyor.
gotoAndStop ("Scene: Bilgi", 1);
}
} else {
// Gerekli alanlar doldurulmamışsa hata sahnesine gönder
gotoAndStop ("Scene: Hata", 1);
}
}
Bu kodlarla mail aldığınızda name, i, validname,
comments ifadelerini göreceksiniz. "i" ifadesi mailde
isim kısmı hariç kullanılan harf sayısını, validname ise geçerli
mail sayısını gösterir. Kodlardan bunları Uygun kelimelerle değiştirebilirsiniz.
Sil butonuna şu kodları yazın:
on (release) {
// Mevcut yazılar silinecek
name = "";
email = "";
comments = "";
}
Scene.Bilgi:
Üstte mailin gönderildiğine dair bir movie klip
eklenmiştir. Alttaki 3 text alanının değişken adını aynı bırakın.
Yalnız her üçünde de dinamik test seçeneğini kullanın. Geri dön
butonuna şu kodları ekleyin:
on (release) {
// Formda mevcut yazılar geri dönerken silinecektir
name = "";
email = "";
comments = "";
// Ana sahneye dönüş
gotoAndStop ("Scene: Form", 1);
}
Scene.Hata:
Gönder butonundaki şartlar sağlanmadığında gidilecek
sahnedir. Bir hata notu ve geri dön butonu ekleyin.
on (release) {
// tekrar yazılması için anasayfaya gönderiliyor.
gotoAndStop ("Scene: Form", 1);
}
Yukardaki kodları butona atayın. Herşey hazır.Publish
komutu ile elinizde 2 dosya olacaktır. 1.index.html
ve flashformmail.swf dosyası. Buna ezformml.cgi
ekleyin ve servera gönderin.
Dikkat: Gönder butonundaki kodları
incelediğinizde LoadVariable komutu ile cgi dosyasının flash kodlarıyla
buluştuğunu göreceksiniz. Buradaki dizini cgi dosyasının bulunduğu
dizin ile değiştirmelisiniz. Ayrıca cgi dosyasında '/usr/lib/sendmail';yazan alanı kendi serverınızın desteklediği dizinle
değiştirmelsiniz.