使用PHP发送AS3变量并发送电子邮件

时间:2013-06-08 21:27:28

标签: actionscript-3

我正在制作一个包含输入框和提交按钮的网站上的Flash内容。用户应在输入框中回答问题,当他点击提交时,应将答案发送到电子邮件地址。问题是,当用户输入答案时,我会收到一封包含以下内容的电子邮件:

array (
)

。这是我的代码:

AS3代码:

var myData:URLVariables = new URLVariables();
myData.answer = answer.text;
var myRequest:URLRequest = new URLRequest("example.php");
myRequest.data = myData;
myRequest.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

按钮的代码:

myButton.addEventListener(MouseEvent.CLICK, sen) ;
function sen(Event:MouseEvent):void
{
navigateToURL( new URLRequest("example.php"), "_self");
}

PHP代码:

<?php
$text = var_export($_POST, true);
$to = "webhosting4@outlook.com";
$subject="Message from php";
mail($to,$subject,$text,"Content-Type: text/plain; charset=utf-8");
?>

那么,我做错了什么?

1 个答案:

答案 0 :(得分:1)

myButton.addEventListener(MouseEvent.CLICK, sen) ;

function sen(Event:MouseEvent):void
{
   var myData:URLVariables = new URLVariables();
   myData.answer = answer.text;

   var myRequest:URLRequest = new URLRequest("example.php");
   myRequest.data = myData;
   myRequest.method = URLRequestMethod.POST;

   var loader:URLLoader = new URLLoader();
   loader.dataFormat = URLLoaderDataFormat.VARIABLES;
   loader.load( myRequest );
};