简体   繁体   English

从as3向php发送变量到电子邮件

[英]sending a variable to an email from as3 to php

I'm working on a flash content on my website that contains an input box and a submit button. 我正在网站上处理Flash内容,其中包含一个输入框和一个提交按钮。 The user should put an answer of a question in the input box and when he clicks on submit, the answer should be sent to an email address. 用户应在输入框中输入问题的答案,然后单击“提交”,答案应发送到电子邮件地址。 The problem is, when a user enters an answer, I receive an empty email message. 问题是,当用户输入答案时,我会收到一封空电子邮件。 Here are my codes: 这是我的代码:

Text box's code: 文本框的代码:

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

The button's code: 按钮的代码:

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

and this is the PHP code: 这是PHP代码:

<?php
$answer = $_POST['answer']; 
$to = "MyMail@example.com";
$subject="Message from php";
mail($to,$subject,$text,"Content-Type: text/plain; charset=utf-8");
?>

So what's wrong with it? 那怎么了

You never defined the variable $text in your PHP code. 您从未在PHP代码中定义变量$ text。 You are probably missing in your code something like this: 您可能在代码中缺少以下内容:

$text = $_POST['text'];

or you should use $answer variable instead of the $text variable. 或者您应该使用$ answer变量而不是$ text变量。

You could write some debug code to see what you have submitted from your AS3 code: 您可以编写一些调试代码,以查看您从AS3代码提交的内容:

<?php
$text = var_export($_POST, true);
// not used anyway
// $answer = $_POST['answer']; 
$to = "MyMail@example.com";
$subject="Message from php";
mail($to,$subject,$text,"Content-Type: text/plain; charset=utf-8");
?>

This way you would get an email containing all the POST variables, so you can see which one you need to reference in your $_POST[] array. 这样,您将收到一封包含所有POST变量的电子邮件,因此您可以在$ _POST []数组中看到需要引用的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM