/////////////////////////////
//1. How to use loadvars to send a variable to a php script
//2. How to make the php script grab the variable and process an email form
//3. How to send the variable back to Flash
/////////////////////////////

//Here we use  input boxes with the box variables names called usernamevar, useremailvar and usermessagevar.

//The dynamic box is used to display  the result sent back. The variable name is thestatusboxvar and the box is given the name thestatusbox.

/////////////////////////////
//1.How to use loadvars to send a variable to a php script
/////////////////////////////

//attach to Flash button
on(press){

//create a loadvars object. Give it any name you like here it is myLoadVars.
var myLoadVars = new LoadVars();

// attach the variables from the input boxes to the myLoadVars object. Here they are called theusername, theuseremail and theusermessage but you can call them what you want
myLoadVars.theusername = usernamevar;
myLoadVars.theuseremail = useremailvar;
myLoadVars.theusermessage = usermessagevar;

//display message in the dynamic box
thestatusboxvar = "Processing...";

//send to the php script
myLoadVars.sendAndLoad("http://www.xx.com/theemailform.php", myLoadVars, "POST");

//when processed, the contents of the status box are change and the colors of the box itself are changed
myLoadVars.onLoad = function (){
thestatusbox.backgroundColor = "0xffffff";
thestatusbox.textColor = "0x0000ff";
thestatusboxvar = myLoadVars.thestatusboxvar;

}//end of myLoadVars.onLoad = function (){

}//end of on (press)

/////////////////////////////
//2. How to make the php script grab the variable and process an email form
/////////////////////////////

//In the php file at the top you put:

$username = $_REQUEST['theusername'];
$useremail = $_REQUEST['theuseremail'];
$usermessage = $_REQUEST['theusermessage'];

//This grabs the variables from the loadvars object and assigns each one to a new variable name.

//Now you can process these with the database.....
//or use them for an email form as below

//CHANGE THESE VALUES!!!!!!!:
//enter your email here
$youremail = "youremail@mail.com";

//enter your name
$yourname = "Fred Bloggs";

//enter your subject here
$subject = "Contact from my web site";

//return message
$returnmessage = "Thank you for contacting me. I have received your email and will reply as soon as possible."; 

/////////////////////////////////////////////////////////////////////////////////////////////////////
//No need to change this unless you want to
/////////////////////////////////////////////////////////////////////////////////////////////////////
//this function gets the IP address
function getenvvars()
{
global $login_ip;

$a = getenv("HTTP_X_FORWARDED_FOR"); 
 $b = getenv("REMOTE_ADDR"); 

 if ($a <> "") 
{ 

$posn=0; 
do 
{ 
 $posn++;
 if ($a
{$posn
} == ',') 
{ 
break; 
} 
} while ($posn < strlen($a));

$login_ip = substr($a,0,$posn);
 
} 
else 
{ 

$login_ip = $b; 
} 
}

getenvvars();

$headers = "From: $yourname<$youremail>\n";
$headers .= "X-Sender: <$youremail>\n";
$headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "X-Priority: 2\n"; // Non - urgent message!
$headers .= "Return-Path: $yourname<$youremail>\n";  // Return path for errors 

$yourmessage = "My IP is: " . $login_ip . "\n\n";
$yourmessage .= "My name is: " . $username . "\n\n";
$yourmessage.= "My email is: " . $useremail . "\n\n";
$yourmessage .= "My message is: " . $usermessage . "\n\n";

//send email to yourself
mail($youremail,$subject,$yourmessage,$headers);

//send email to the person who fills in the form
mail($useremail,$subject,$returnmessage,$headers);

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////
//3. How to send the variable back to Flash
/////////////////////////////
//Here you send the return variables back: $authorization is just a name... you can call it whatever you like.

//This just sends back a message to the dynamic text box
$authorization="&thestatusboxvar=Thank you!";
echo $authorization;

//OR to send back a variable, from the database:

$valuereturnedfromdatabase = (whatever);

$authorization="&thestatusboxvar=$valuereturnedfromdatabase";
echo $authorization;

