I have built a series of email forms in flash MX. using perl. the forms work for some people but not all and I was hoping some one could help me out.
Here is the Actionscript on the send button
on (release, keyPress "<Enter>") {
if (company ne "" and first ne "" and last ne "" and phone ne "" and fax ne "" and mobile ne "" and email ne "" and address ne "" and city ne "" and state ne "" and zip ne "") {
i = "0";
validmail = 0;
while (Number(i)<=Num ber(length(emai l))) {
if (substring(emai l, i, 1) eq "@") {
validmail = 1;
}
i = Number(i)+1;
}
// If there's no @ in the email go to the error page.
if (Number(validma il) == 0) {
status = "User Input Error";
} else {
loadVariablesNu m("http://bostongreenreal ty.com/cgi/email.cgi", 0, "POST");
status = "Thank you for signing up";
play();
}
} else {
// if the user left required fields blank, show them an error message.
status = "User Input Error";
}
}
and here is the perl script
#!/usr/bin/perl
$SENDMAIL = '/usr/sbin/sendmail';
@AUTHURLS = ('www.bostongre enrealty.com',' bostongreenreal ty.com');
$TO = 'bostongreenrea lty@gmail.com';
$SUBJECT = 'Mailing List';
$SORT_TYPE = 'none';
@SORT_FIELDS = ('Field1','Fiel d2','Field3','F ield4','Field5' );
############### ############### ############### ############### ############### #
# Check to make sure this script was called by an authorized URL(s)
&check_url;
# Format Local Date/Time for Email Message Date
&get_date;
# Reformat Form Contents
&reformat_form_ data;
# Send the form data to the recipient via e-mail
&send_email;
exit();
############### ############### ############### ############### ####
sub check_url
{
if ($ENV{'HTTP_REF ERER'})
{
foreach $AUTHURL (@AUTHURLS)
{
if ($ENV{'HTTP_REF ERER'} =~ /$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>Unauthor ized URL Referrer - Access Denied</title>\n </head>\n";
print " <body>\n <center>\n <h1>Unauthorize d URL Referrer - Access Denied</h1>\n </center>\n";
print "The form that is trying to use this script resides at: \n";
print "$ENV{'HTTP_REF ERER'}, which is not allowed to access this cgi script.<p>\n";
print "Sorry!\n";
print "</body></html>\n";
exit;
}
}
sub get_date
{
@days = ('Sunday','Mond ay','Tuesday',' Wednesday','Thu rsday','Friday' ,'Saturday');
@months = ('January','Feb ruary','March', 'April','May',' June','July',
'August','Septe mber','October' ,'November','De cember');
($sec,$min,$hou r,$mday,$mon,$y ear,$wday,$yday ,$isdst) = localtime(time) ;
if ($hour < 10)
{ $hour = "0$hour"; }
if ($min < 10)
{ $min = "0$min"; }
if ($sec < 10)
{ $sec = "0$sec"; }
if ($year < 10)
{ $year = "0$year"; }
if ($year < 90)
{ $cent = "20"; }
else
{ $cent = "19"; }
$date = "$days[$wday], $months[$mon] $mday, $cent$year at $hour\:$min\:$s ec";
$mon = $mon + 1;
if ($mon < 10)
{ $mon = "0$mon"; }
if ($mday < 10)
{ $mday = "0$mday"; }
$dateShort = "$cent$year \-$mon\-$mday";
$timeShort = "$hour\:$min\:$ sec";
}
sub reformat_form_d ata
{
if ($ENV{'REQUEST_ METHOD'} eq 'POST')
{
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_L ENGTH'});
# 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{'HT TP_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{$nam e}, $value";
}
elsif ($value)
{
$FORM{$name} = $value;
}
}
}
sub send_email
{
# Build the 'from' address of the form: "name <email address>"
$from_name=($CO NFIG{'Name'} . " <" . $CONFIG{'email' } . "> ");
open(MAIL,"|$SE NDMAIL -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 message header with the Local Date/Time
print MAIL "---------------------------------------------------------------\n\n";
print MAIL " The following information was submitted by: \n";
print MAIL " $CONFIG{'Name'} on $date\n\n";
print MAIL "---------------------------------------------------------------\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_FI ELD})
{
print MAIL "$SORT_FIEL D: $FORM{$SORT_FIE LD}\n\n";
}
}
}
else
{
foreach $key (keys %FORM)
{
print MAIL "$key: $FORM{$key}\n\n ";
}
}
# Output the mail footer
print MAIL "<REMOTE HOST> $ENV{'REMOTE_HO ST'}\n";
print MAIL "<REMOTE ADDRESS> $ENV{'REMOTE_AD DR'}\n";
print MAIL "<USER AGENT> $ENV{'HTTP_USER _AGENT'}\r\n";
# Close the pipe and send the mail
close(MAIL);
}
Thanks
Grevo.