Hi all,
I created a flash contact form however, when the user hits the send button, the only information that is sent to my email is the $subject. The user $email, $name,and $message is usually blank. Sender comes back as CGI-MAILER. Here is the code from the flash file :
// hide processing//
processing_mc.visible = false;
// Variables to connect to PHP//
var variables:URLVariables = new URLVariables;
//varSend Variable//
var varSend:URLRequest = new URLRequest("form_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// build the varLoader variable//
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE,completeHandler);
//Handler for the PHP script completion and return of status//
function completeHandler(event:Event):void{
//remove processing clip//
processing_mc.visible = false;
name_txt.text = "";
email_txt.text = "";
msg_txt.text = "";
//Load the response from php here
status_txt.text = event.target.data.return_msg;
}
//add event listener for submit button click //
submit.addEventListener(MouseEvent.CLICK,ValidateAndSend);
//function ValidateAndSend//
function ValidateAndSend(event:MouseEvent):void{
//validate fields
if(!name_txt.length){
status_txt.text = "Please enter your name";
}else if(!email_txt.length){
status_txt.text = "Please enter your email";
}else if(!msg_txt.length){
status_txt.text = "Please enter your message";
}else {
//All is good, send the data now to PHP
processing_mc.visible = true;
//ready the variables in our form for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userMsg = msg_txt.text;
//Send the data to PHP now
varLoader.load(varSend);
}// close else condition for error handling
}//close validate and send function
And here is the code from the PHP file on my server :
<?php
//creat local variables from the flash Actionscript posted variables
$senderName=$_POST['userName'];
$senderEmail=$_POST['userEmail'];
$senderMessage=$_POST['userMsg'];
//Your send information
$to="me@example.com";
$from="$senderEmail";
$subject="Website Inquiery";
$message="Website Message Inquiery:
Name:$senderName
Email:$senderEmail
Message Inquery:$senderMessage";
//build$header Variable
$headers="From: $from\r\n";
$headers="Content-type: text\r\n";
$to="$to";
//send the email
mail($to,$subject,$message,$headers);
// message that goes back to flash
$my_msg="Thanks $senderName, all data has been sent.";
print "return_msg=$my_msg";
exit();
?>
Any ideas?
[edited by: jatar_k at 5:45 pm (utc) on Mar 16, 2010]
[edit reason] examplified email [/edit]