繁体   English   中英

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

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

我正在网站上处理Flash内容,其中包含一个输入框和一个提交按钮。 用户应在输入框中输入问题的答案,然后单击“提交”,答案应发送到电子邮件地址。 问题是,当用户输入答案时,我会收到一封空电子邮件。 这是我的代码:

文本框的代码:

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;

按钮的代码:

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

这是PHP代码:

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

那怎么了

您从未在PHP代码中定义变量$ text。 您可能在代码中缺少以下内容:

$text = $_POST['text'];

或者您应该使用$ answer变量而不是$ text变量。

您可以编写一些调试代码,以查看您从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");
?>

这样,您将收到一封包含所有POST变量的电子邮件,因此您可以在$ _POST []数组中看到需要引用的变量。

暂无
暂无

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

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