Skip to main content
Known Participant
February 19, 2007
Question

getting PHP to communicate with FLASH

  • February 19, 2007
  • 13 replies
  • 77951 views
Im having some issues getting my flash contact form to communicate with my form.PHP I have been scouring tutorials but im just not getting what exactly goes into the PHP file. My variables are different from the tutorials I have seen. This is what I have

I guess my main question is how do I set up the PHP file so that it can work with my flash files?
This topic has been closed for replies.

13 replies

Inspiring
February 22, 2007
I see one thing that stands out. It's the $phone variable.

Here is the syntax (from php.net) for the mail function

bool mail ( string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]] )

According to your php file, the following information is being sent.....

$to is right
$subject is right
$message is right
$phone is wrong (this should be sent inside the body of your message if you want their phone number)... according to the mail functions parameters, this would be header information and since this is going to be ###-###-#### and not of the form MIME blah blah blah, the server receiving the e-mail is going to reject it. change your mail line to this....

mail($to, $subject, $message, $headers)

also change the variable call to message to this....

$message = $_POST['visitor_comments']." ".$_POST['visitor_phone'];

and get rid of the $phone = $_POST['visitor_phone']; line as it won't be necessary.
kglad
Community Expert
Community Expert
February 22, 2007
unzip the files i sent. upload the html file and php file using ascii protocol. upload to the same directory the swf file using binary protocol. retest.
em_shomerAuthor
Known Participant
February 22, 2007
Ok last question, and then I will shut up because I am sure everybody is annoyed with this thread. I just dont understand why it can work one place and not the other. I changed the email address, thinking maybe that had something to do with it. Im not sure if my hosting company supports sending email to an external address, so I invented a new email that has the same domain name and updated that in both my PHP and swf files, and still nothing, but I can tell it is communicating because there is a small delay when i hit the send button which is why I think it is receiving the data in the PHP file but it is not sending. If you could check the PHP file one more time and see if you can pick out anything that looks odd, I would appreciate it.
kglad
Community Expert
Community Expert
February 22, 2007
if you're not getting the email from my test link it's because the email address is incorrect (which i know you've checked) OR my server has restrictions on using their server sending emails to non-authorized recipients (which is highly likely).

but if you're having trouble using your server check your servers email policies. that email address may not be an authorized recipient of emails sent from your server.
em_shomerAuthor
Known Participant
February 22, 2007
correction it will go to the frame label now that I have the PHP in the same location as the SWF. but still no email I will check with the server to make sure that email will work
kglad
Community Expert
Community Expert
February 22, 2007
i corrected the php file and the swf.

the test link was missing a w so you can retest yourself with the obvious addition of the third w.

i also sent a test email using the contact form which you should receive sometime after 8:40am pst.
em_shomerAuthor
Known Participant
February 22, 2007
Still no email. I am using the original PHP and Swf sent in the zip file from last evening. I can still get to the frame label that says the message was sent, but there is no email.

<?php
$to = "eric.shomer@gmail.com";
$name = $_POST['visitor_name'];
$email = $_POST['visitor_email'];
$message = $_POST['visitor_comments'];
$phone = $_POST['visitor_phone'];
$subject = 'A Message from a Bodyshop client';


$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:'. $name .' <' . $email . '>' . "\r\n";

$ok = mail($to, $subject, $message, $phone, $headers);
if($ok) {
echo "&response=passed&";
} else {
echo "&response=failed&";
}

?>


SWF******
this.stop();
// -------------------<send form LoadVars>------------------- \\
var gatherForm:LoadVars = new LoadVars();
var receiveForm:LoadVars = new LoadVars();
receiveForm.onLoad = function() {
if (this.response == "passed") {
name_txt.text = "";
email_txt.text = "";
phone_txt.text = "";
msg_txt.text = "";
trace("email sent");
gotoAndStop("correct");
}
};
function sendForm() {
gatherForm.email_to = "eric.shomer@gmail.com";
gatherForm.visitor_comments = msg_txt.text;
gatherForm.visitor_name = name_txt.text;
gatherForm.visitor_email = email_txt.text;
gatherForm.visitor_phone = phone_txt.text;
// You may want to try the absolute http to this file i.e. http://www.mydomain.com/form.php
// If you are testing on the local system and it doesn't know how to parse php,
// you'll never get a response back from the file.
gatherForm.sendAndLoad(" http://www.bodyshopfitnesscenter.com/sources/Flash/form.php", receiveForm, "POST");
}
// -------------------</send form LoadVars>------------------- \\
//--------------------<submit button AS>---------------------\\
// onRelease
submitBtn.onRelease = function() {
if (email_txt.text == "" || phone_txt.text == "" || name_txt.text == "" || msg_txt.text == "") {
gotoAndStop("error");
} else {
sendForm();
}
};
//--------------------</submit button AS>---------------------\\

kglad
Community Expert
Community Expert
February 22, 2007
is your email address correct in the php file? do you receive an email when you test contactForm.html on the above site?
em_shomerAuthor
Known Participant
February 22, 2007
Well email is correct in PHP file as well as Flash File. I would have liked to try it out on your site, but unfortunatly link is broken
Inspiring
February 22, 2007
There were some issues in the original PHP file. I'm not sure if you ever corrected those but they existed in the mail() line which meant that the e-mail would never send. Below is the correct php file. Just copy and paste and then insert your e-mail in the correct line. Try it again, and get back to me.
kglad
Community Expert
Community Expert
February 22, 2007
em_shomerAuthor
Known Participant
February 22, 2007
Thanks for the help...I am still having a problem. I am able to advance to the correct frame label, but nothing is happening. I am not getting emails. Perhaps there is something either with my email or on the server. I appreciate your help
Inspiring
February 21, 2007
What did you do based on my last post? No offense, but it's not customary for us to write people step by step instructions for everything. We assume that people have a pretty basic understanding of the technology they wish to use. Getting aggravated because you don't know php or actionscript isn't going to solve the problem.

And be specific.... What exactly is not working? Are you not getting the e-mail? Is it not going to the frame label you want? What are the instance names of each text field in the form? Do these match exactly to those in your sendForm function to be sent by LoadVars? Does your server support PHP and if so, does it allow mail()? This stuff all makes a huge difference. Have you tried to use the php file on it's own in an html form? If not, I'd try that first.

Another idea, post the fla file and the php file via zip. kglad, myself and others will gladly download it and look at it to see what if anything we notice. There may be other conflicts inside your fla file that are botching up the LoadVars etc that you may not see. A fresh set of eyes never hurts. Giving us the code many times is not going to be enough to give the clearest picture of the problem. We'd rather you learn than get frustrated and give up.
em_shomerAuthor
Known Participant
February 22, 2007
Please understand it is very hard to communicate effectivly in a message board when you are new to something I have a basic understanding of the material, but i dont know anything about PHP, hence the reason I am here. Anyway I would really like to get this fixed and see what my mistake is. If anybody is willing to take a look at it and help me out with it I would really appreciate it. Furthermore If you are able to get it working I will be happy to compensate for your troubles.
I am attaching a link to a zip file of the contact form, PHP and swf files.

link
em_shomerAuthor
Known Participant
February 20, 2007
what im saying is: pretend I dont have a PHP script...by looking at actionscript posted above. How would you set up the PHP.
Inspiring
February 21, 2007
Ok. I've included your code with a few additions.

First and foremost, whenever I'm sending data from a contact form, I always make sure to do something with the response so that I know first hand that the backend php communications are working. This is often times just a simple trace during testing to see what response was received by LoadVars.

Examining your AS, I noticed a few things.

First, you used mail.php as your file. If you are testing on the local system, this isn't going to work...not unless you have a PHP parser installed and running on your system when you are testing inside Flash. You need to rewrite the url and include the full URL to the file on the webserver i.e. www.mydomain.com/php/mail.php or whatever the url is for the mail.php file on your server.

Second, you are sending the user off to "correct" before you even know for sure that there was a successful communication with the mail.php file at all. I added a second LoadVars to your AS as well as changed the line gatherForm.send(...) to gatherForm.sendAndLoad(....). This way, you know for certain that the file in question (mail.php) is both legit, ready and working and you'll also know that you have received the data back from that file.
em_shomerAuthor
Known Participant
February 21, 2007
still not working...but thanks for the effort...i officially give up
kglad
Community Expert
Community Expert
February 20, 2007
there should be nothing to setup except to be sure you swf and your php script are in the same directory, your php is receiving all the variable/values it expects and your php script has permissions granted to be read and executed by everyone.
em_shomerAuthor
Known Participant
February 20, 2007
i left my email out on purpose...

can you maybe or someone just explain how to set up the PHP form from my actionscript posted:

stop();

// -------------------<send form LoadVars>------------------- \\
var gatherForm:LoadVars = new LoadVars();

function sendForm() {
gatherForm.email_to = "eric.shomer@gmail.com";
gatherForm.visitor_comments = eComments.text;
gatherForm.visitor_name = eName.text;
gatherForm.visitor_email = eEmail.text;
gatherForm.visitor_phone = ePhone.text;

gatherForm.send("form.php", "POST");
}
// -------------------</send form LoadVars>------------------- \\

//--------------------<submit button AS>---------------------\\

// onRelease
submitBtn.onRelease = function() {
if (eEmail.text == "" || ePhone.text =="" || eName.text == "" || eComments.text == "") {
gotoAndStop("error");
} else {
sendForm();
gotoAndStop("correct");
}
}

//--------------------</submit button AS>---------------------\\