Link to home
Start Free TrialLog in
Avatar of isaacr25
isaacr25

asked on

Help with flash email form and php

Ok,
I need some help with flash and email, using php for the script.
I'm following the kirupa tutorial here:
http://www.kirupa.com/developer/actionscript/flash_php_email.htm

I've attached the email script I'm using, and you can download the email fla here:
www.mwebdev.com/emailtest.fla.

No success yet... please help. Thanks in advance.
<?php
$sendTo = "MyEmailIsHereInTheRealScript@hotmail.com";
$subject = "Email from website";
 
// variables are sent to this PHP page through
// the POST method.  $_POST is a global associative array
// of variables passed through this method.  From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
 
 
// header information not including sendTo and Subject
// these all go in one variable.  First, include From:
$headers = "From: " . $_POST["Name"] . "<" . $_POST["Email"] .">\r\n";
$headers = "From: " . $_POST["Phone"]"\n";
// next include a replyto
$headers .= "Reply-To: " . $_POST["Email"] . "\r\n";
// often email servers won't allow emails to be sent to
// domains other than their own.  The return path here will
// often lift that restriction so, for instance, you could send
// email to a hotmail account. (hosting provider settings may vary)
// technically bounced email is supposed to go to the return-path email
$headers .= "Return-path: " . $_POST["Email"];
 
// now we can add the content of the message to a body variable
$message = $_POST["Message"];
 
 
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $message, $headers);
 
?>

Open in new window

Avatar of Zeffer
Zeffer
Flag of New Zealand image

It all looks pretty much right..but try..
this.form.loadVariables("contact.php", "POST");
as without the 'this' the player will be trying to reference _root

Z
Avatar of isaacr25
isaacr25

ASKER

Z,
That did not seem to make a difference. Other thoughts?
Avatar of hielo
The From header needs to be set to a valid email address. You are overwriting it with a phone value. Try
<?php
$sendTo = "MyEmailIsHereInTheRealScript@hotmail.com";
$subject = "Email from website";
 
// variables are sent to this PHP page through
// the POST method.  $_POST is a global associative array
// of variables passed through this method.  From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
 
 
// header information not including sendTo and Subject
// these all go in one variable.  First, include From:
$headers = "From: " . $_POST["Name"] . "<" . $_POST["Email"] .">\n"; 
// next include a replyto
$headers .= "Reply-To: " . $_POST["Email"] . "\n";
$headers .="To:" . $sendTo ."\n";
// often email servers won't allow emails to be sent to
// domains other than their own.  The return path here will
// often lift that restriction so, for instance, you could send
// email to a hotmail account. (hosting provider settings may vary)
// technically bounced email is supposed to go to the return-path email
$headers .= "Return-path: " . $_POST["Email"];
 
// now we can add the content of the message to a body variable
$headers = "Phone: " . $_POST["Phone"]"\n";
$message .= $_POST["Message"];
 
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $message, $headers);
 
?>

Open in new window

SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No success yet.
You will need to set the variables in your flash:

try using the loadVars object

var lv:LoadVars = new LoadVars()

lv.Email = "someone@domain.com";
lv.Message = "this is your message";
... set the others as well ie. phone etc

lv.send("contact.php", "_self", "POST");
tagit,
It looks as though the values of the fields are hard-coded... I don't quite understand.
can you confirm that your php script is receiving the data?

I would still use the loadVars class but give instance names to the textboxes

txtEmail
txtPhone
txtMessage

that way you can pick up their values:

lv.Email = txtEmail.text;
lv.Message = txtMessage.text;
I must apologize. Looking over my post yet again, I realize that this:
$headers = "Phone: " . $_POST["Phone"] . "\n";

should have been:
$message= "Phone: " . $_POST["Phone"] . "\n";

Save the code below as email.php
<?php
$sendTo = "MyEmailIsHereInTheRealScript@hotmail.com";
$subject = "Email from website";
 
// variables are sent to this PHP page through
// the POST method.  $_POST is a global associative array
// of variables passed through this method.  From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
 
 
// header information not including sendTo and Subject
// these all go in one variable.  First, include From:
$headers = "From: '" . $_POST["Name"] . "'<" . $_POST["Email"] .">\n"; 
// next include a replyto
$headers .= "Reply-To: " . $_POST["Email"] . "\n";
$headers .="To:" . $sendTo . "\n";
// often email servers won't allow emails to be sent to
// domains other than their own.  The return path here will
// often lift that restriction so, for instance, you could send
// email to a hotmail account. (hosting provider settings may vary)
// technically bounced email is supposed to go to the return-path email
$headers .= "Return-path: " . $_POST["Email"];
 
// now we can add the content of the message to a body variable
$message = "Phone: " . $_POST["Phone"] . "\n";
$message .= $_POST["Message"];
 
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $message, $headers);
 
?>

Open in new window

Once you save email.php as suggested above, then save the code below as hielo.html in the same folder where you saved email.php. Then open hielo.html on your browser, complete the form and submit it. My goal here is to make sure your server is actually able to send emails out.
<html>
<body>
<form method="post" action="email.php">
	<div>Name:<input type="text" name="Name" value=""/></div>
	<div>Email:<input type="text" name="Email" value=""/></div>
	<div>Message:<textarea name="Message"></textarea></div>
<div><input type="submit" value="Submit"/></div>
</form>
</body>
</html>

Open in new window

hielo,
I made your change to the email.php file, and I tested the server using your small form. I received the email successfully using your form, but emails from my swf are still not sending.
>>I received the email successfully using your form
Great. At least you have email.php working now. What you had before was not going to email at all. Step iv of the tutorial has this:
form.loadVariables("email.php", "POST");

type the full url to your emai.php script MINUS your domain - ex:
if the path to email.php is
http://www.yoursite.com/yourscripts/email.php OR
http://localhost/yourscripts/email.php

remove the domain so that your "new path" is:
form.loadVariables("/yourscripts/email.php", "POST");

Notice that it starts with a slash. You will of course need to supply YOUR ACTUAL path since /yourscripts/email.php is just an example
hielo,
I've tried what you suggested, and still no success. If you have time, please see my full fla here and see if you can figure out what's wrong. Thanks for your time.

www.mwebdev.com/email.fla
I don't have flash so I can't help you there. We know for a fact that your email.php is now working correctly, so I suggest you read over the tutorial to make sure you did the other steps correctly.
Hi - modify your actionscript to use what i have suggested above.  in fact i'll modify it and reupload
Please stay posted for further updates tomorrow while I test the changes. Thanks for all your help guys.
tagit,
No luck yet. I used the the flash file you posted, and I used the php code that is attached. When I click the Submit button, the browser navigates to the php script (in address bar, just a blank page). The email never sends.
<?php
$sendTo = "myrealemailwashere@hotmail.com";
$subject = "Email from website";
 
// variables are sent to this PHP page through
// the POST method.  $_POST is a global associative array
// of variables passed through this method.  From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
 
 
// header information not including sendTo and Subject
// these all go in one variable.  First, include From:
$headers = "From: '" . $_POST["Name"] . "'<" . $_POST["Email"] .">\n"; 
// next include a replyto
$headers .= "Reply-To: " . $_POST["Email"] . "\n";
$headers .="To:" . $sendTo . "\n";
// often email servers won't allow emails to be sent to
// domains other than their own.  The return path here will
// often lift that restriction so, for instance, you could send
// email to a hotmail account. (hosting provider settings may vary)
// technically bounced email is supposed to go to the return-path email
$headers .= "Return-path: " . $_POST["Email"];
 
// now we can add the content of the message to a body variable
$message = "Phone: " . $_POST["Phone"] . "\n";
$message .= $_POST["Message"];
 
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $message, $headers);
 
?>

Open in new window

tagit,
Concerning my last post.

CORRECTION: The email did sent successfully, however this is what came through:

Phone: undefined
undefined
OK try changing the function from send() to sendAndLoad() and i hadn't referenced the form properly so the code becomes:

on (release) {
      // send variables in form movieclip (the textfields)
      // to email PHP page which will send the mail
      //this.form.loadVariables("dev3/mom/contact.php", "POST");
      var lv:LoadVars = new LoadVars();
      lv.Email = _parent.form.txtEmail.text;
      lv.Message = _parent.form.txtMessage.text;
      lv.Phone = _parent.form.txtPhone.text;
      lv.Name = _parent.form.txtName.text;
      trace(_parent.form);
      lv.sendAndLoad("dev3/mom/contact.php","","POST");
}
tagit,
Still no luck. Now when I hit the submit button, nothing happens.
ok i think we're getting closer as i've got it to work for me, though i've ignored the Phone field for now (which i'm unsure why you had in the header...)

my php script is attached and you can download the updated fla i've used: http://users.tpg.com.au/rjurd/email.fla (give it a minute if it's not there yet)
<?php
$sendTo = "me@mydomain.com";
$subject = "Email from website";
 
// variables are sent to this PHP page through
// the POST method.  $_POST is a global associative array
// of variables passed through this method.  From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
 
 
// header information not including sendTo and Subject
// these all go in one variable.  First, include From:
if (array_key_exists("Name", $_POST)) {
	$headers = "From: " . $_POST["Name"] . "<" . $_POST["Email"] .">\r\n";
	// next include a replyto
	$headers .= "Reply-To: " . $_POST["Email"] . "\r\n";
	// often email servers won't allow emails to be sent to
	// domains other than their own.  The return path here will
	// often lift that restriction so, for instance, you could send
	// email to a hotmail account. (hosting provider settings may vary)
	// technically bounced email is supposed to go to the return-path email
	$headers .= "Return-path: " . $_POST["Email"];
 
	// now we can add the content of the message to a body variable
	$message = $_POST["Message"];
 
 
	// once the variables have been defined, they can be included
	// in the mail function call which will send you an email
	mail($sendTo, $subject, $message, $headers);
}
else {
	echo "
		<html>
		<body>
		<form method=\"post\" action=\"index.php\">
				<div>Name:<input type=\"text\" name=\"Name\" value=\"\"/></div>
				<div>Email:<input type=\"text\" name=\"Email\" value=\"\"/></div>
				<div>Phone:<input type=\"text\" name=\"Phone\" value=\"\"/></div>
				<div>Message:<textarea name=\"Message\"></textarea></div>
		<div><input type=\"submit\" value=\"Submit\"/></div>
		</form>
		</body>
		</html>
	";
}
?>

Open in new window

When you hit the Submit button, does anything happen?
yes i get an email with all the data
just be aware that this will not work in the flash IDE unless you specify a web server ie

"http://server/scripts/dev3/mom/contact.php"

your "dev3/mom/contact.php" will not work unless you are viewing it from a web browser http://server/scripts/flash.html
What I mean is does the swf do anything? I'm still not getting an email.
I'm uploading all files to my webserver each time I test.
no the swf doesn't do anything because you haven't asked it to.

You will see in the code below how to handle when you get a response from the server that the email has been sent as long as the php script echos the following:

echo "LVResult=email sent successfully";
on (release) {
	// send variables in form movieclip (the textfields)
	// to email PHP page which will send the mail
	//this.form.loadVariables("dev3/mom/contact.php", "POST");
	var lv:LoadVars = new LoadVars();
	var lvR:LoadVars = new LoadVars();
	
	lvR.onLoad = function(success:Boolean) {
		trace(this.LVResult);
	}
	lv.Email = _parent.form.txtEmail.text;
	lv.Message = _parent.form.txtMessage.text;
	lv.Phone = _parent.form.txtPhone.text;
	lv.Name = _parent.form.txtName.text;
	
	//lv.send("dev3/mom/contact.php","_self","POST");
	lv.sendAndLoad("http://itadmin/projects/ee/email/index.php", lvR, "POST");
}

Open in new window

you can use the lvR.onLoad function to change the page of the swf to say that the email has been sent successfully or not
What is this line pointing to?

lv.sendAndLoad("http://itadmin/projects/ee/email/index.php", lvR, "POST");

And should I change it?
yes you will need to change it to the full path of your php script
Ok,
Progress! The email came through, but only the message from the Message field came through.
what do you want the message to say?

so from this:

name: andrew
phone: 555-5555
email: name@address.com
message: i think this works

what do you want to be in the body of the email?
It should say exactly as you've typed it:

name: andrew
phone: 555-5555
email: name@address.com
message: i think this works
ok then your php needs to change slightly

instead of:

$message = $_POST["Message"];

add the other fields in:

$message = "Name: " . $_POST["Name"] . "\n";
$message .= "Phone: " . $_POST["Phone"] . "\n";
$message .= "Email: " . $_POST["Email"] . "\n";
$message .= "Message: " . $_POST["Message"] . "\n";
All right. We did it! :)
excellent! :) so it works now the way you want it to?
One more thing! I know I'm being a pain in the hiney!

The fla file you used was a stripped down file, so now I'm trying to edit the "real" fla to match the changes you made. So, please tell me if there is anything else in addition to these steps:

-Instance names of Form and Submit button
-Instance and Var names for each of the text fields in the form
-The following code behind the form:
on (release) {
      // send variables in form movieclip (the textfields)
      // to email PHP page which will send the mail
      //this.form.loadVariables("dev3/mom/contact.php", "POST");
      var lv:LoadVars = new LoadVars();
      var lvR:LoadVars = new LoadVars();
      
      lvR.onLoad = function(success:Boolean) {
            trace(this.LVResult);
      }
      lv.Email = _parent.form.txtEmail.text;
      lv.Message = _parent.form.txtMessage.text;
      lv.Phone = _parent.form.txtPhone.text;
      lv.Name = _parent.form.txtName.text;
      
      //lv.send("dev3/mom/contact.php","_self","POST");
      lv.sendAndLoad("http://realdomainhere.com/contact.php", lvR, "POST");
}

Is there anything else?
the on(release) does need to be on the submit button, not the form but other than that you're ready to go!
Now that I've made these changes to my "real" .fla and upload to the webserver, the email is not coming through! Arrrrggggghhhhh!
what happens when you navigate to the php page i gave you above?
When I go to <domainhere>.com/contact.php, a form appears with fields for name, email, phone, and message.
and when you fill out the form and submit it does it send the email?
It tries to navigate to index.php, which does not exist, and the email hasn't come through.
tagit,
Please see my last post. Thanks for your help.
change the php file to navigate to itself.  it was designed so that you can test that the email works
tagit,
I changed the routing back to itself, contact.php. So, filling out the small form, the email comes through successfully. Its still not sending from the swf. What's next?
ok this is good in a way.

Check the path that the flash is calling ie. in your on(release)

      lv.sendAndLoad("http://realdomainhere.com/contact.php", lvR, "POST");

what happens when you type the url exactly as you see it in your sendAndLoad function into a web browser?
It brings me to the same form that was used before. I filled out and submitted the form and the email was again sent successfully.
If it would help, should I email you a download link to the "real" fla for you to take a look? I'm baffled. I don't want to post the download link publicly.
that should be ok as long as we still discuss the issue here.   i would suggest uploading it to your ftp site and i'll let you know when i've got it so that you can delete it
Here is the link:
www.mwebdev.com/final.fla
Please let me know when you have it.
ok got it
have you uploaded your swf to that site? ie final.swf / final.html?
I just uploaded final.swf and final.html

www.mwebdev.com/final.html

Thanks.
sorry i meant when i visited the website you have in your fla i couldnt access the html file.  Where are you trying to run this from? the swf/html/php all need to be in the same directory on the same webserver
I think that may have been my problem all along! I placed the html, swf, and php files in the same directory, and the email worked!

One more thing...When I enter a second email address in the php file, the email doesn't work. I'm using:

$sendTo = "email1@hotmail.com; email2@hotmail.com";

Is this the correct syntax for multiple email addresses?
use commas for multiple email addresses

glad it's finally working! ;)
Awesome! Now I just have to figure out how to display a confirmation message to the user.

Thanks greatly for your patience and for sticking with me!
well based on what the php form sends back to the flash you can move to 1 of 2 frames.  one saying that their email has been sent successfully or one saying that there was an error and to try again later
tagit,
I'm about to lose my mind here. I've now uploaded the site to a different server (the "real" server), and I'm no longer receiving the emails correctly! When I navigate directly to contact.php and fill out the form, I get the email fine. Its when I use the flash email form that its not working. Could a different server be an issue with the flash form?
Please see my last post. In addition, now it seems like a couple of the emails are working. Some come through... some don'! What would make this script work intermittently?
The flash MUST be on the same server as the contact.php because there is a security feature in flash that will not allow cross domain communication.

If you do have it on the same server in the same directory then it is possible that your mail server is flagging the email as spam.  i've had the same issue myself and had to look around for a php mail class that constructs the email in such a way as to not be marked as spam.
also do not try to send it to more than one person in the $sendTo variable.  instead add a header for BCC
Everything is in the same directory, and I've sending to one recipient. Would the spam issue be an intermittent one?
Yes definitely.  To make it better the FROM should have the same domain as the domain you are sending from ie. website@domain.com.au then you should be on www.domain.com.au
It doesn't look like I currently have a From header in the php file (which I've attached). Where would I add this?
<?php
$sendTo = "emailhere@cox.net";
$subject = "Email from website";
 
// variables are sent to this PHP page through
// the POST method.  $_POST is a global associative array
// of variables passed through this method.  From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
 
 
// header information not including sendTo and Subject
// these all go in one variable.  First, include From:
if (array_key_exists("Name", $_POST)) {
	$headers = "From: " . $_POST["Name"] . "<" . $_POST["Email"] .">\r\n";
	// next include a replyto
	$headers .= "Reply-To: " . $_POST["Email"] . "\r\n";
	// often email servers won't allow emails to be sent to
	// domains other than their own.  The return path here will
	// often lift that restriction so, for instance, you could send
	// email to a hotmail account. (hosting provider settings may vary)
	// technically bounced email is supposed to go to the return-path email
	$headers .= "Return-path: " . $_POST["Email"];
 
	// now we can add the content of the message to a body variable
	$message = "Name: " . $_POST["Name"] . "\n";
	$message .= "Phone: " . $_POST["Phone"] . "\n";
	$message .= "Email: " . $_POST["Email"] . "\n";
	$message .= "Message: " . $_POST["Message"] . "\n";
 
 
 
	// once the variables have been defined, they can be included
	// in the mail function call which will send you an email
	mail($sendTo, $subject, $message, $headers);
}
else {
	echo "
		<html>
		<body>
		<form method=\"post\" action=\"contact.php\">
				<div>Name:<input type=\"text\" name=\"Name\" value=\"\"/></div>
				<div>Email:<input type=\"text\" name=\"Email\" value=\"\"/></div>
				<div>Phone:<input type=\"text\" name=\"Phone\" value=\"\"/></div>
				<div>Message:<textarea name=\"Message\"></textarea></div>
		<div><input type=\"submit\" value=\"Submit\"/></div>
		</form>
		</body>
		</html>
	";
}
?>

Open in new window

it's this line:

      $headers = "From: " . $_POST["Name"] . "<" . $_POST["Email"] .">\r\n";

you will have to change this to come from the webserver but i would put their details into the $message variable
tagit,
Excuse my ignorance. How would I change this line to reflect coming from www.website.com?

And what do you mean by putting their details in the $message variable?
:) like this:

$headers = "From: Website Enquiry <webmaster@website.com>\r\n";

currently the message is what ever the user types right? so you can just add their name, phone, email to the top of the message that you get ie.

if i filled out the form like this:

Name: John Smith
Phone: 555-5555
Email: user@mydomain.com
Message:  I love your food

Then I would create the $message variable to be:

$message = "The following comments have been submitted:\r\n";
$message .= "Name: " . $_POST["Name"] . "\r\n";
$message .= "Phone: " . $_POST["Phone"] . "\r\n";
$message .= "Email: " . $_POST["Email"] . "\r\n";
$message .= "Comments: " . $_POST["Message"] . "\r\n";
Ok,
Using the code attached, no emails are coming through, even directly from contact.php.
<?php
$sendTo = "realemailreplace@hotmail.com";
$subject = "Email from website";
 
// variables are sent to this PHP page through
// the POST method.  $_POST is a global associative array
// of variables passed through this method.  From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
 
 
// header information not including sendTo and Subject
// these all go in one variable.  First, include From:
if (array_key_exists("Name", $_POST)) {
	$headers = "From: Website Enquiry <info@realdomainreplaced.com>\r\n";
	// next include a replyto
	$headers .= "Reply-To: " . $_POST["Email"] . "\r\n";
	// often email servers won't allow emails to be sent to
	// domains other than their own.  The return path here will
	// often lift that restriction so, for instance, you could send
	// email to a hotmail account. (hosting provider settings may vary)
	// technically bounced email is supposed to go to the return-path email
	$headers .= "Return-path: " . $_POST["Email"];
 
	// now we can add the content of the message to a body variable
	$message = "The following comments have been submitted:\r\n";
	$message .= "Name: " . $_POST["Name"] . "\r\n";
	$message .= "Phone: " . $_POST["Phone"] . "\r\n";
	$message .= "Email: " . $_POST["Email"] . "\r\n";
	$message .= "Comments: " . $_POST["Message"] . "\r\n";
 
 
 
 
	// once the variables have been defined, they can be included
	// in the mail function call which will send you an email
	mail($sendTo, $subject, $message, $headers);
}
else {
	echo "
		<html>
		<body>
		<form method=\"post\" action=\"contact.php\">
				<div>Name:<input type=\"text\" name=\"Name\" value=\"\"/></div>
				<div>Email:<input type=\"text\" name=\"Email\" value=\"\"/></div>
				<div>Phone:<input type=\"text\" name=\"Phone\" value=\"\"/></div>
				<div>Message:<textarea name=\"Message\"></textarea></div>
		<div><input type=\"submit\" value=\"Submit\"/></div>
		</form>
		</body>
		</html>
	";
}
?>

Open in new window

I gave you woking code to send email on my third post. Try changing all those \r\n to just \n
Yes sorry didn't mean to bring back that booboo ;)  You also should have the Reply-To to be the same as the From:

ie:

$headers .= "Reply-To: info@realdomainreplaced.com\n";
tagit,
I made the changes. This seems to help, but its still intermittent. This morning, 2 out of 4 tries were successful in sending the emails.
ok I thought it we could get away with it it would be ok BUT see this post from the php.net site:

Are you getting spammed while sendig emails using php mail() function to yahoo or hotmail?

 It is a common problem for all using php mail function. To solve this there
are so many answers I have seen in the internet and they do not hit problem
correctly.

Actually the problem here is if we send mails using php mail function we do
not have a signature and other mailing systems thinks that we are spamers.

So the solution is using a free remote smtp host like gmail to send our mails.
It is not hard because we have a free php smtp project called PHPMailer. You
can download it from http://sourceforge.net/project/showfiles.php?group_id=26031.
You do not need to install it on your server and you can upload it to the server with your code.

It is very easy to understand how it is used to send mails using examples
zipped with PHPMailer. The following code is to send emails using gmail and
to do that you have to have a gmail mail account. Which can easily be created
by visiting http://gmail.com. Your mails will
send using that mail account and they will never become spams...

You can follow the following link to get the code to send emails using gmail's free smtp service.
http://bestdeveloper.blogspot.com/
What you are going to need to do is use a class (PHPMailer) that conforms to the RFC 2822 standard of sending email messages and more than likely use an SMTP connection to the server you are hosting the site with.
tagit,
You've helped me as much as you can I think. I just need to do some research based on your last posts and get a good understanding of the email functions.

Concerning this post of yours:
"well based on what the php form sends back to the flash you can move to 1 of 2 frames.  one saying that their email has been sent successfully or one saying that there was an error and to try again later"
Can you help me here? Let me know if I should open another post for this since it's a different question. Thanks.
no that's fine, it should be answered here as it relates to the overall structure.

When your php script sends an email it returns either true or false, you can then return that value to flash to be able to go to a success or failure page.

so for instance:

<?php

....

// this line is if the mail sent ok set the mail-status variable to "OK" otherwise set it to "BAD"
$mail_status = (mail(.....)) ? "OK" : "BAD";
echo "result=$mail_status";

....

?>

THEN IN FLASH

on (release) {
      // send variables in form movieclip (the textfields)
      // to email PHP page which will send the mail
      //this.form.loadVariables("dev3/mom/contact.php", "POST");
      var lv:LoadVars = new LoadVars();
      var lvR:LoadVars = new LoadVars();
     
      lvR.onLoad = function(success:Boolean) {
            trace(this.result);
            // based on what is returned go to the relevant keyframe labels
            if(this.result == "OK") {
                gotoAndStop("Success");  // could be gotoAndStop(5) etc but i like using labels
            }
            else {
                gotoAndStop("Failure");
            }
      }
      lv.Email = _parent.form.txtEmail.text;
      lv.Message = _parent.form.txtMessage.text;
      lv.Phone = _parent.form.txtPhone.text;
      lv.Name = _parent.form.txtName.text;
     
      //lv.send("dev3/mom/contact.php","_self","POST");
      lv.sendAndLoad("http://realdomainhere.com/contact.php", lvR, "POST");
}
Well,
Back to the intermittent email problem. It seems like the email always sends successfully directly from the contact.php form, but not always from the flash form. Why is this???
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tagit,
I'm not leaving any fields blank when I test (is that what you're asking?). It hasn't failed once yet using the contact.php form directly.

zeffer,
Is this an entirely different way of doing it? Please explain your post further. Thanks.
Yes it's different.
It's self explanatory.

Z
What is the response you are getting in flash?  Add the alert component to notify you of the response from the server so that you can debug the live version
Try as Zeffer has suggested, and z ditto :)
Guys, I've divided up the points for this question based on the volume of input that you gave. I hope you think this is fair... you all were really helpful. I just decided to go in a different direction (non-flash form). Thanks for all your suggestions.