I have a problem with sending a PHP contact form from a flash site. All my code is below.
The contact form gets stuck on the sending... bit (and nothing happens when clicking submit).

Firstly, may I point out that if I copy both the flash .swf file and the .php file that it works when uploaded to a different server.
It was recently moved to a new server which does support php (so not sure why it does not work).

The web hosts believe there may be a problem with the code (perhaps thinking that there is a small error which was more forgiving on the old server?). They also advised to remove the _POST from the .php file, but this did not work either.

send_email.php file:

< ? php
$contact_name = $_POST['name'];
$contact_tel = $_POST['tel'];
$contact_email = $_POST['email'];
$contact_subject = $_POST['subject'];
$contact_feedback = $_POST['feedback'];
$contact_message = $_POST['message'];

if( $contact_name == true )
{
	$sender = $contact_email;
	$receiver = "me@gmail.com";
	$client_ip = $_SERVER['REMOTE_ADDR'];
	$email_body = "Name: $contact_name \nTel: $contact_tel \nEmail: $sender \nDate: $contact_subject \nFeedback: $contact_feedback \nMessage: $contact_message";		
	$extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

if( mail( $receiver, "My Contact Form - $subject", $email_body, $extra ) ) 
{
	echo "success=yes";
}
else
{
	echo "success=no";
}
}
?>

This is the code on the flash file:

send_button.onRelease = submit;
reset_button.onRelease = reset;
function submit() {
	if (contact_name.text == "" || contact_tel.text == "" || contact_email.text == "") {
		message_status.text = "Please enter your name, tel and an email address.";
	} else if  ( 
	contact_email.text.indexOf('@')<2 || contact_email.text.indexOf('.')<0) {
		message_status.text = "Please enter a valid email address.";
	} else {
		message_status.text = "";
		gotoAndStop("send");
	}
}
function reset() {
	contact_name.text = contact_feedback.text=contact_tel.text=contact_email.text=contact_subject.text=contact_message.text=message_status.text="";
	clearInterval(interval_id);
	gotoAndStop("stop");
}

This is the code from the send frame (again on the same flash file):

stop();
loadVariables("send_email.php?flashmo=" + random(1000), this, "POST");
message_status.text = "sending...";
var i = 0;
function check_status()
{
	if( success == "yes" )
	{
		message_status.text = "Your message was sent successfully!";
		play();
	}
	else if( success == "no" )
	{
		message_status.text = "Your message could not be sent. Please try again.";
		gotoAndStop("stop");;
	}
	if( i >= 20 )
		clearInterval(interval_id);
	i++;
}
var interval_id = setInterval(check_status, 400);

(ActionScript v2 flash player 9)

any ideas?
thanks,
mark.

    < ? php

    should be

    <?php

    no spaces

      sorry,
      the space was just a mistake on the post. There is no space on my form.
      thanks.

        Hi Barnsley,

        The line

        if( $contact_name == true )

        looks like it will always fail. You might want to change that to something like

        if( $contact_name != '' )

          I tried this:
          if( $contact_name != '' )
          but with no luck.

          I ran a php script on its own which resulted in a basic php email being sent ok - so no problem with mail.
          - guess it's down to flash or the php somewhere.

          would a trace / error trap to prove anything?

          I've found the original source code: http://www.flashmo.com/preview/flashmo_102_contact_form

          and downloaded a copy - this works ok (so I must have an error somewhere), I will post here if i find it.
          thanks.

            Working now!
            I downloaded another copy of the source files and built the form again.
            The original files worked, yet even when I copied this into my existing form it failed again!
            - which led me to believe that it was a permissions issue on the server - of all things!

            bizarrely - uploading from one folder gave the file full permissions (777) - which failed.
            But changing this to 755 - was a success! (limiting groups and others write permissions).

            anyone else having problems with this - re-download the source files and test again -
            http://www.flashmo.com/preview/flashmo_102_contact_form
            mark.

              Write a Reply...