Link to home
Start Free TrialLog in
Avatar of J N
J N

asked on

flash contact form with php

Hi,
i have a flash contact form that is used for the user and a php that takes the data and sends it to the email i have specified.  it works other than one glitch. it seems when i send it the email message reads oh no....! however i receive the email

the oh no (error message) is generated by a timer but i cant seem to figure it out.

The flash code is as follows
/*************************************    
Buttons       
**************************************/ 

sendbtn.addEventListener(MouseEvent.CLICK, submit);

resetbtn.addEventListener(MouseEvent.CLICK, reset); 

/*************************************        
Variables needed        
**************************************/  

 var timer:Timer; var varLoad:URLLoader = new URLLoader;

 var urlRequest:URLRequest = new URLRequest( "mail.php" );

 urlRequest.method = URLRequestMethod.POST;

/*************************************
Functions
**************************************/ 

 function init():void{

 //Set all fields to empty

 yourName.text = "";

 fromEmail.text = "";

 yourSubject.text = "";

 YourMsg.text = "";

 }

 function submit(e:MouseEvent):void{

 //Check to see if any of the fields are empty

 if( yourName.text == "" || fromEmail.text == "" || yourSubject.text == "" || YourMsg.text == "" ) { valid.text = " All fields need to be filled.";

 }

 //Check if you're using a valid email address

 else if( !checkEmail(fromEmail.text) )

 { valid.text = "Enter a valid email address"; } 


else { valid.text = "Sending over the internet...";

 var emailData:String = "name=" + yourName.text + "&from=" + fromEmail.text + "&subject=" + yourSubject.text + "&msg=" + YourMsg.text;

var urlVars:URLVariables = new URLVariables(emailData);
urlVars.dataFormat = URLLoaderDataFormat.TEXT;
urlRequest.data = urlVars; varLoad.load( urlRequest );
varLoad.addEventListener(Event.COMPLETE, thankYou );
 } 
}
function reset(e:MouseEvent):void{
init(); //call the initial clear function
 }
function checkEmail(s:String):Boolean {

 //This tests for correct email address

var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/; var
r:Object = p.exec(s);
if( r == null ) {
return false;

}

return true;

}

function thankYou(e:Event):void { 
var loader:URLLoader =
URLLoader(e.target); 
var sent = new
URLVariables(loader.data).sentStatus; if( sent == "yes" )
{
valid.text = "Thanks for your email!"; 
timer = new Timer(5000);
timer.addEventListener(TimerEvent.TIMER, msgSent);
timer.start();
}
else {
valid.text = "Oh no! Something is wrong! Try again..."; }

}

function msgSent(te:TimerEvent):void {
if( timer.currentCount >= 10 ) { init();
timer.removeEventListener(TimerEvent.TIMER, msgSent);

}

}

Open in new window


mail.php
<title>DEMO</title>
<?php $yourName = $_POST['name']; // the variable needs to match your Actionscript

$fromEmail = $_POST['from']; // the variable needs to match your Actionscript

$yourSubject = $_POST['subject']; // the variable needs to match your Actionscript

$YourMsg = $_POST['msg']; // the variable needs to match your Actionscript

if( $yourName == true ) { $sender = $fromEmail; $yourEmail ="jayme.nagy@ncca.co"; // This will be your email address so please change this

$ipAddress = $_SERVER['REMOTE_ADDR']; // This gets the user's ip Address

$emailMsg = "Name: $yourName sent this from IP:
$ipAddress\n\nReturn Email: $sender
\n\nSubject:$yourSubject\n\nMessage:\n\n$YourMsg \n\nThis email was sent using a form on your site";$return = "From: $sender\r\n" .
"Reply-To:$sender \r\n" ."X-Mailer: PHP/" . phpversion();

if( mail( $yourEmail, "$yourSubject", $emailMsg, $return
))

{ 
echo "sentStatus=yes"; }

else { echo "sentStatus=no"; } }
?> 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India 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
Avatar of J N
J N

ASKER

hi,

i apologize this took me a while but i have been working on a different project. im not sure where i would post that