Hello I tried to make a contact form for my Flash website but when I upload it to my server it just doesn't work. Can you tell me what is wrong with my codes or doesn't it work because of a server-side problem?
Here is my Actionscript code on Flash:

import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;

InteractiveObject(theName.getChildAt(1)).tabIndex = 1;
InteractiveObject(theEmail.getChildAt(1)).tabIndex = 2;
InteractiveObject(theMessage.getChildAt(1)).tabIndex = 3;

var allVars:URLVariables = new URLVariables();
var asdLoader:URLLoader = new URLLoader();
var mailAddress:URLRequest = new URLRequest("mailer.php");

send_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_7);

function fl_MouseClickHandler_7(event:MouseEvent):void
{

	if (theName.text == "" || theEmail.text == "" || theMessage.text == "")
	{
		theFeedback.text = "PLease fill all fields.";
	}
	else
	{
		allVars.name = theName.text;
		allVars.email = theEmail.text;
		allVars.message = theMessage.text;
		mailAddress.data = allVars;
		mailAddress.method = URLRequestMethod.POST;
		asdLoader.addEventListener(Event.COMPLETE, loaded);
		asdLoader.load(mailAddress);
		theName.text = "";
		theEmail.text = "";
		theMessage.text = "";
	}
}

function loaded(e:Event):void
{
	theFeedback.text = asdLoader.data;
}

here is the code of mailer.php

<?php



$name = $_REQUEST["name"];
$message = $_REQUEST["message"];
$to = $_REQUEST["email"];

$message = stripslashes($message); 
$name = stripslashes($name); 
$to = stripslashes($to); 

if(isset($message) and isset($subject) and isset($sender)){
	
	mail("johndoe@gmail.com", "mail from the website", $message, "From: $to");
}
?>

Thanks in advance!

Dani AI

Generated

Quick summary: the form can fail for either client-side (Flash) or server-side reasons. was right to suggest using POST, but the bigger problems in the posted PHP will prevent any useful response from the server: the script checks the wrong variable names (so the mail() block never runs) and it never echoes a status string back to the Flash loader, so the SWF will always see an empty response. Also, clearing the form fields before you know the mail succeeded makes debugging harder.

Server-side fixes to try first:

  • Use $_POST and validate each field (non-empty + valid email).
  • Prevent header-injection by stripping CR/LF from the sender email.
  • Echo a short success/failure message so the Flash loader can show feedback.
  • Turn on temporary error reporting while debugging.

Example (minimal) PHP handler to return clear responses and reduce risks:

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo 'Invalid request'; exit; }

$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$msg  = trim($_POST['message'] ?? '');

if ($name==='' || $email==='' || $msg==='') { echo 'Please fill all fields'; exit; }
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo 'Invalid email'; exit; }

$email = str_replace(array("\r","\n","%0a","%0d"), '', $email);
$to = 'johndoe@gmail.com';
$headers = "From: $email\r\nReply-To: $email";
if (mail($to, 'Contact form', $msg, $headers)) echo 'Message sent'; else echo 'Mail failed';
?>

Client-side/Flash tips:

  • Add listeners for IOErrorEvent and SecurityErrorEvent to catch network/security problems and show their text.
  • Do not clear input fields until the loader returns a success message.
  • If the SWF and PHP are on different domains, ensure a permissive crossdomain.xml is present or use the same host during testing.

Quick checklist: hit mailer.php directly (or POST via curl/simple HTML form) to see its output, enable PHP errors while debugging, inspect Flash error events, and if mail() is unreliable on the host switch to SMTP (PHPMailer) for production.

Recommended Answers

All 3 Replies

I don't know much about action script, but your PHP code is correct, although a small thing I noticed, line 21 says PLease, Won't effect the code though, just wanted to point that out.

Possibly change $_REQUEST to $_POST though.

Thanks but converting to $_POST didn't work. And about PLease, it writes in another language in the actual code, I translated it to English before posting here and made a mistake there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.