phils13776
New Member
- Messages
- 18
- Reaction score
- 0
- Points
- 0
Hello all,
Im having problems setting up an email form using action script 3 and php. I have tried numerous variation of forms with no luck. The form is up on the site. It confirms that the message was sent. However i never get a message on my hosted email. PLZ HELP!
HERE IS THE ACTION SCRIPT (sample that Im using):
// Set text formatting colors for errors, waiting..., and success mechanisms
var errorsFormat:TextFormat = new TextFormat();
errorsFormat.color = 0xFF0000;
var waitingFormat:TextFormat = new TextFormat();
waitingFormat.color = 0x339900;
var successFormat:TextFormat = new TextFormat();
successFormat.color = 0x3366FF;
// hide the little processing movieclip
processing_mc.visible = false;
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
var varSend:URLRequest = new URLRequest("http://www.lavidapictures.com/contact_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 PHP script completion and return
function completeHandler(event:Event):void{
// remove processing movieclip
processing_mc.visible = false;
// Clear the form fields
name_txt.text = "";
email_txt.text = "";
msg_txt.text = "";
// Load the response from the PHP file
status_txt.text = event.target.data.return_msg;
status_txt.setTextFormat(successFormat);
}
// Add an event listener for the submit button and what function to run
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// Validate form fields and send the variables when submit button is clicked
function ValidateAndSend(event:MouseEvent):void{
//validate form fields
if(!name_txt.length) {
status_txt.text = "Please enter your name.";
status_txt.setTextFormat(errorsFormat);
} else if(!email_txt.length) {
status_txt.text = "Please enter an email address";
status_txt.setTextFormat(errorsFormat);
} else if(!validateEmail(email_txt.text)) {
status_txt.text = "Please enter a VALID email address";
status_txt.setTextFormat(errorsFormat);
} else if(!msg_txt.length) {
status_txt.text = "Please enter a message.";
status_txt.setTextFormat(errorsFormat);
} else {
// All is good so send the message to the parse file
// Show the little "processing_mc" movieclip
processing_mc.visible = true;
// Ready the variables for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userMsg = msg_txt.text;
// Send the data to the php file
varLoader.load(varSend);
// Put a temporary message in the response field while the PHP file sends back
// If the code does not connect to the PHP file this message will remain visible to user
status_txt.text = "Waiting for server connection...";
status_txt.setTextFormat(waitingFormat);
} // close else after form validation
} // Close ValidateAndSend function //////////////////////////////////////////////////////////////
// Validate email function
function validateEmail(str:String):Boolean {
var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var result:Object = pattern.exec(str);
if(result == null) {
return false;
}
return true;
}
////////////////////////////////////
HERE IS THE PHP SCRIPT:
<?
// Create local variables from the Flash ActionScript posted variables
$senderName = $_POST['userName'];
$senderEmail = $_POST['userEmail'];
$senderMessage = $_POST['userMsg'];
// Strip slashes on the Local variables for security
$senderName = stripslashes($senderName);
$senderEmail = stripslashes($senderEmail);
$senderMessage = stripslashes($senderMessage);
// IMPORTANT - Change these lines to be appropriate for your needs - IMPORTANT
$to = "bryan@lavidapictures.com";
$from = "$senderEmail";
$subject = "Contact from your site";
// Modify the Body of the message however you like
$message = "Message from your website:
Their Name: $senderName
Their Email: $senderEmail
Their Message is below: $senderMessage";
// Build $headers Variable
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";
$to = "$to";
// Send the email
mail($to, $subject, $message, $headers);
// Assemble the message that goes back to Flash
// The flash ActionScript is looking for a return variable of "return_msg"
$my_msg = "Thanks $senderName, your message has been sent.";
// Print the data back to flash who is patiently waiting for it in the onCompleteHandler
print "return_msg=$my_msg";
// Exit script
exit();
?>
Im having problems setting up an email form using action script 3 and php. I have tried numerous variation of forms with no luck. The form is up on the site. It confirms that the message was sent. However i never get a message on my hosted email. PLZ HELP!
HERE IS THE ACTION SCRIPT (sample that Im using):
// Set text formatting colors for errors, waiting..., and success mechanisms
var errorsFormat:TextFormat = new TextFormat();
errorsFormat.color = 0xFF0000;
var waitingFormat:TextFormat = new TextFormat();
waitingFormat.color = 0x339900;
var successFormat:TextFormat = new TextFormat();
successFormat.color = 0x3366FF;
// hide the little processing movieclip
processing_mc.visible = false;
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
var varSend:URLRequest = new URLRequest("http://www.lavidapictures.com/contact_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 PHP script completion and return
function completeHandler(event:Event):void{
// remove processing movieclip
processing_mc.visible = false;
// Clear the form fields
name_txt.text = "";
email_txt.text = "";
msg_txt.text = "";
// Load the response from the PHP file
status_txt.text = event.target.data.return_msg;
status_txt.setTextFormat(successFormat);
}
// Add an event listener for the submit button and what function to run
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// Validate form fields and send the variables when submit button is clicked
function ValidateAndSend(event:MouseEvent):void{
//validate form fields
if(!name_txt.length) {
status_txt.text = "Please enter your name.";
status_txt.setTextFormat(errorsFormat);
} else if(!email_txt.length) {
status_txt.text = "Please enter an email address";
status_txt.setTextFormat(errorsFormat);
} else if(!validateEmail(email_txt.text)) {
status_txt.text = "Please enter a VALID email address";
status_txt.setTextFormat(errorsFormat);
} else if(!msg_txt.length) {
status_txt.text = "Please enter a message.";
status_txt.setTextFormat(errorsFormat);
} else {
// All is good so send the message to the parse file
// Show the little "processing_mc" movieclip
processing_mc.visible = true;
// Ready the variables for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userMsg = msg_txt.text;
// Send the data to the php file
varLoader.load(varSend);
// Put a temporary message in the response field while the PHP file sends back
// If the code does not connect to the PHP file this message will remain visible to user
status_txt.text = "Waiting for server connection...";
status_txt.setTextFormat(waitingFormat);
} // close else after form validation
} // Close ValidateAndSend function //////////////////////////////////////////////////////////////
// Validate email function
function validateEmail(str:String):Boolean {
var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var result:Object = pattern.exec(str);
if(result == null) {
return false;
}
return true;
}
////////////////////////////////////
HERE IS THE PHP SCRIPT:
<?
// Create local variables from the Flash ActionScript posted variables
$senderName = $_POST['userName'];
$senderEmail = $_POST['userEmail'];
$senderMessage = $_POST['userMsg'];
// Strip slashes on the Local variables for security
$senderName = stripslashes($senderName);
$senderEmail = stripslashes($senderEmail);
$senderMessage = stripslashes($senderMessage);
// IMPORTANT - Change these lines to be appropriate for your needs - IMPORTANT
$to = "bryan@lavidapictures.com";
$from = "$senderEmail";
$subject = "Contact from your site";
// Modify the Body of the message however you like
$message = "Message from your website:
Their Name: $senderName
Their Email: $senderEmail
Their Message is below: $senderMessage";
// Build $headers Variable
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";
$to = "$to";
// Send the email
mail($to, $subject, $message, $headers);
// Assemble the message that goes back to Flash
// The flash ActionScript is looking for a return variable of "return_msg"
$my_msg = "Thanks $senderName, your message has been sent.";
// Print the data back to flash who is patiently waiting for it in the onCompleteHandler
print "return_msg=$my_msg";
// Exit script
exit();
?>