Forum Moderators: coopster

Message Too Old, No Replies

Flash PHP form sending blank Emails.

php flash form sending blank email

         

mysticfire

4:37 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



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]

Matthew1980

8:26 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there mysticfire,

Welcome to the forum!

Only a bit of advice really, concerning your $_POST variables:-

$senderName = strip_tags($_POST['userName']);
$senderEmail = strip_tags($_POST['userEmail']);
$senderMessage = strip_tags($_POST['userMsg']);


Add strip tags to the array so that if anyone tries to post bad or malicious code, this function will strip it out.

Whether this is the result of the mods or not, I can't say, but this needs changing too:-

$from = $senderEmail;

$to = $to; //delete this line as the var is already declared


and:


$my_msg = "Thanks ".$senderName.", all data has been sent.";


That will just add the var to the string now ;-p

and also:-


$message = "Website Message Enquiry:\n\r";
$message .= "\n\r";
$message .= "Name:".$senderName."\n\r";
$message .= "Email:".$senderEmail."\n\r";
$message .= "Message Enquiry:"\n\r";
$message .= "\n\r";
$message .= $senderMessage."\n\r";


That takes care of the formatting ;-p

There are other ways of formatting but as this is the example that you supplied I thought it best not to deviate from your preferred method.

[EDIT] Oops just noticed this:-

//build$header Variable
$headers = "From: ".$from."\r\n";
$headers .= "Content-type: text\r\n";


Your building a string so the '=' needs to be joined with the '.' operator.

Other than that I can't see anything else.

Hope that's clearer now for you.

Cheers,
MRb