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.