# Flash / PHP Mail form problem

**URL:** <https://forum.kirupa.com/t/flash-php-mail-form-problem/159075>\
**Category:** flash\
**Created:** [August 14, 2005, 3:02pm UTC](https://forum.kirupa.com/t/flash-php-mail-form-problem/159075 "2005-08-14T15:02:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chromis](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@chromis](https://forum.kirupa.com/u/chromis)\
**Post date:** [August 14, 2005, 3:02pm UTC](https://forum.kirupa.com/t/flash-php-mail-form-problem/159075/1 "2005-08-14T15:02:44Z")

</div>

Hi,

Having read numerous tutorials (including the one held on kirupa) on flash / php mail forms I have managed to get mail sent to an email address. However when I add validation functions or use validation functions I seem to run into problems. It would appear from the output of the php file that the validation happens successfully, however the mail function has ceased to work!?

The flash file contains the following:  
Layer 1 - frame labels  
Layer 2 - stop methods for the five frames  
Frame 1  
stop();  
Frame 2  
stop();  
Frame 3  
stop();  
Frame 4  
stop();  
Frame 5  
stop();  
Layer 3 -  
Frame 1 - spans the 5 frames  
Actionscript for the form (see below)  
Layer 4 -  
Frame 1  
bttnSubmit - Submit button  
Layer 5 -  
Frame 1 - spans the 5 frames  
textAlert - debugging alert textbox  
Layer 6 -  
Frame 1  
Form: textName, textEmail, textMessage  
Frame 2  
textProcessing (Processing msg text box)  
Frame 3  
textError (Server Error msg text box)  
Frame 4  
textInvalid (Invalid email msg text box)

The actionscript contained in layer 3 is:

[AS]  
dataSender = new LoadVars();  
dataReceiver = new LoadVars();  
/_DEFINE SUBMIT BUTTON BEHAVIOR_/  
bttnSubmit.onRelease = function() {  
//final check to make sure fields are completed  
if (textName.text != ‘’ && textEmail.text != ‘’ && textMessage.text != ‘’) {  
textAlert.text = "Text in fields " . textEmail.text;  
//clear any previous error messages or warnings  
//advance playhead to frame 2 - the “processing” message  
\_root.play();  
//assign properties to LoadVars object created previously  
dataSender.name = textName.text;  
dataSender.email = textEmail.text;  
dataSender.message = textMessage.text;  
//callback function - how to handle what comes back  
dataReceiver.onLoad = function() {  
if (this.response == “invalid”) {  
\_root.gotoAndStop(‘contactError’);  
} else if (this.response == “error”) {  
\_root.gotoAndStop(‘contactError’);  
} else if (this.response == “passed”) {  
\_root.gotoAndStop(‘contactLoop’);  
}  
};  
//now send data to script  
dataSender.sendAndLoad(“processEmail.php”, dataReceiver, “POST”);  
} else {  
//warning if user tries to submit before completing form  
textAlert.text = “Please complete all fields before submitting form.”;  
}  
};  
[/AS]

The processEmail.php file contains:

```auto

 <?php
 
   $name=$_POST['name'];
   $email=$_POST['email'];
   $message=$_POST['message'];
   $name=trim($name);
   $email=trim($email);
 
   $name=StripSlashes($name);
   $message=StripSlashes($message);
 
   $toAddress = "excess_euphoria@hotmail.com";
   $subject = "Message from website";
 
   $headers = "From: " . $_POST["name"];
   $headers .= "<" . $email . ">
";
   $headers .= "Reply-To: " . $email . "
";
   $headers .= "Return-Path: " . $email;
 
 function validate_email($email) {
   global $HTTP_HOST;
   if (eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) {
 	return 0;
   }
   else {
 	return 1;
   }
 }
 
 $valid = validate_email($email);
 
 switch ($valid) {
   case 0:
 	mail($toaddress,$subject,$message,$headers);
 	//clear the variables
 	$name='';
 	$email='';
 	$subject='';
 	$message='';
 	echo 'response=passed';
 	break;
   case 1:
 	 echo 'response=invalid';
 	 break;
   case 2:
 	 echo 'response=error';
 	 break;
 }//end switch
 
 ?>
 

```

The pieces of code have been simplifed from code found in tutorials. All that I wish to do for now is have the email address validated correctly and have the flash file behave properly, responding to the output from the php.

I hope this is detailed enough for someone to help, thankyou.

- chromis
