我使用的是Flash CS6和flash player 11.4
以下是使用 PHP
从 Flash 发送电子邮件的示例as3代码:
var php_file = "simple_email.php";
var message_text = "Hello Im mesage from flash.";
function sendEmail():void
{
var myData:URLVariables = new URLVariables();
myData.msg = message_text;
var myRequest:URLRequest = new URLRequest(php_file);
myRequest.data = myData;
myRequest.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
try {
loader.load(myRequest);
} catch (error:Error) {
trace("Unable to load URL");
}
function completeHandler(e:Event):void {
trace("Data Content:"+e.target.data)
trace("Response:"+e.target.data.success);
};
};
sendEmail();
php代码:
<?php
$msg = $_POST["msg"];
$to = "webhosting4@outlook.com";
$subject="Message from php";
$success = mail($to,$subject,$msg,"Content-Type: text/plain; charset=utf-8");
echo "temp=1&success=".$success;
?>
一切看起来很简单,但不起作用
1)响应:应为true或false,并且是:&#34;。$ success; ?&gt; (解析不好?)
2)e.target.data看起来很奇怪:
Data Content:success=%22%20%24success%3B%0D%0A%3F%3E&%3C%3Fphp%0D%0A%09%24msg%20=%20var%5Fexport%28%24%5FPOST%2C%20true%29%3B%0D%0A%09%24to%20%3D%20%22baca%2Erene%40gmail%2Ecom%22%3B%0D%0A%09%24subject%3D%22Message%20from%20php%22%3B%0D%0A%09%24success%20%3D%20mail%28%24to%2C%24subject%2C%24msg%2C%22Content%2DType%3A%20text%2Fplain%3B%20charset%3Dutf%2D8%22%29%3B%0D%0A%09echo%20%22temp%3D1
3)执行代码后我没有收到任何电子邮件......一定是错的?
答案 0 :(得分:0)
按顺序:
In PHP Booleans do not echo out "true" or "false" like they do in actionscript-3s trace()。您需要在PHP中使用某种形式的if语句来回显相应的字符串,而不是直接回显该变量。
e.target.data
返回你的PHP代码的utf转义字符串版本,这通常表示php没有执行,文件只是作为字符串读取,你应该检查您的服务器配置正确并检查PHP错误日志(并更改您的php config to write all errors to the log)
是的,出了点问题,检查你的PHP配置和错误日志,很有可能和SMTP配置错误。
你也可以在php中使用error_get_last();
来提取php抛出的最后一个错误。