簡體   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