Copy link to clipboard
Copied
Hello I am creating a contact form in Flash with AS3 and I am getting this error message:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///Macintosh%20HD/Users/animationmanx/Desktop/mail.php
at ContactMovie_fla::MainTimeline/sendMessage()
Here is the code
<?php
$to = "myemailHere.com";
$subject = ($_POST['senderName']);
$message = ($_POST['senderMsg']);
$message .= "\n\n---------------------------\n";
$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
if(@mail($to, $subject, $message, $headers))
{
echo "answer=ok";
}
else
{
echo "answer=error";
}
?>
submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);
function sendMessage(e:MouseEvent):void{
var my_vars:URLVariables = new URLVariables();
my_vars.senderName = name_txt.text;
my_vars.senderEmail = email_txt.text;
my_vars.senderMsg = message_txt.text;
var my_url:URLRequest = new URLRequest("mail.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
name_txt.text = "";
email_txt.text = "";
message_txt.text = "Message Sent";
}
I do have my real email in there I just took it out for this post.
you already have that set:
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
so you shouldn't see that error message if you're testing the code you posted.
Copy link to clipboard
Copied
there's no mail.php found in Macintosh%20HD/Users/animationmanx/Desktop/
Copy link to clipboard
Copied
Ok thanks I fixed that but now it says:
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
Copy link to clipboard
Copied
assign your loader's dataFormat property to 'variables'.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
you already have that set:
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
so you shouldn't see that error message if you're testing the code you posted.
Copy link to clipboard
Copied
I am still getting this message
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
Copy link to clipboard
Copied
then you're not using the code you posted or your local computer doesn't support php.
Copy link to clipboard
Copied
What should I do?
Copy link to clipboard
Copied
copy and paste your actionscript into a new fla with those textfields and that button.
publish an html and swf and upload both to a server (that supports php).
copy that php to a text file, name it mail.php and upload to the same directory as your html and swf.
test.
Copy link to clipboard
Copied
Here is my code:
submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);
function sendMessage(e:MouseEvent):void{
var my_vars:URLVariables = new URLVariables();
my_vars.senderName = name_txt.text;
my_vars.senderEmail = email_txt.text;
my_vars.senderMsg = message_txt.text;
var my_url:URLRequest = new URLRequest("mail.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
name_txt.text = "";
email_txt.text = "";
message_txt.text = "Message Sent";
}
Copy link to clipboard
Copied
i'm not sure what you mean by posting that last message.
again,
copy and paste your actionscript into a new fla with those textfields and that button.
publish an html and swf and upload both to a server (that supports php).
copy that php to a text file, name it mail.php and upload to the same directory as your html and swf.
Copy link to clipboard
Copied
It seemed to work like you said once I uploaded it to my website server. However, I haven't received the email.
Copy link to clipboard
Copied
did you remember to change that email address?
Copy link to clipboard
Copied
Thank you I just saw I didn't change it in the php file.
Copy link to clipboard
Copied
so, all's well?
Copy link to clipboard
Copied
Well, I thought so but the email never showed up in my inbox. Here is exactly what I have in the actionscript. And I uploaded the php file too.
this.stop();
<?php
$to = "myemailHERE";
$subject = ($_POST['senderName']);
$message = ($_POST['senderMsg']);
$message .= "\n\n---------------------------\n";
$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
if(@mail($to, $subject, $message, $headers))
{
echo "answer=ok";
}
else
{
echo "answer=error";
}
?>
submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);
function sendMessage(e:MouseEvent):void{
var my_vars:URLVariables = new URLVariables();
my_vars.senderName = name_txt.text;
my_vars.senderEmail = email_txt.text;
my_vars.senderMsg = message_txt.text;
var my_url:URLRequest = new URLRequest("mail.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
name_txt.text = "";
email_txt.text = "";
message_txt.text = "Message Sent";
}
Copy link to clipboard
Copied
you need to change this line:
$to = "myemailHERE";
Copy link to clipboard
Copied
I have the right email in that spot I just changed it for the purpose of this post. Is it right that I posted the php in the action script panel as well as uploading a separate file to my server?
Copy link to clipboard
Copied
no php should be in your actionscript. if it is, you should see compiler errors.
the php needs to be in a file named mail.php saved without text formatting (like ms windows would add). ie, use a plain text editor like notepad or wordpad.
Copy link to clipboard
Copied
I just got it to work completely. That must have been the last problem. That I made the php file using ms word. Thank you for all the help, I really appreciate it!!!
Copy link to clipboard
Copied
you're welcome.