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)<=Number(length(email))) {
if (substring(email, i, 1) eq "@") {
validmail = 1;
}
i = Number(i)+1;
}
// If there's no @ in the email go to the error page.
if (Number(validmail) == 0) {
status = "User Input Error";
} else {
loadVariablesNum("http://bostongreenrealty.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.bostongreenrealty.com','bostongreenrealty.co m');
$TO = 'bostongreenrealty@gmail.com';
$SUBJECT = 'Mailing List';
$SORT_TYPE = 'none';
@SORT_FIELDS = ('Field1','Field2','Field3','Field4','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_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 get_date
{
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday ','Friday','Saturday');
@months = ('January','February','March','April','May','June' ,'July',
'August','September','October','November','Decembe r');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = 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\:$sec";
$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_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>"
$from_name=($CONFIG{'Name'} . " <" . $CONFIG{'email'} . "> ");
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 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_FIELD})
{
print MAIL "$SORT_FIELD: $FORM{$SORT_FIELD}\n\n";
}
}
}
else
{
foreach $key (keys %FORM)
{
print MAIL "$key: $FORM{$key}\n\n";
}
}
# Output the mail footer
print MAIL "<REMOTE HOST> $ENV{'REMOTE_HOST'}\n";
print MAIL "<REMOTE ADDRESS> $ENV{'REMOTE_ADDR'}\n";
print MAIL "<USER AGENT> $ENV{'HTTP_USER_AGENT'}\r\n";
# Close the pipe and send the mail
close(MAIL);
}
Thanks
Grevo.