Flash 中的联系表单:AS3 检查 php 是否发送了电子邮件*问题*
Flash 中的联系表单,采用 AS3 转 PHP。
我的问题是 AS3 中的函数“showdata”不从 PHP 代码中获取变量。它无法从 PHP 看到data=success,所以即使电子邮件已成功发送,我总是收到“错误”。 您能帮助我建议在“showdata”功能或其他功能中更改哪些内容吗?
我正在在线服务器上进行测试
PHP 代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$subject =$_POST[theme];
$message=$_POST[msg];
$mail_from=$_POST[email];
$header="from: $name <$mail_from>";
$to ='[email protected]';
$sending=mail($to,$subject,$message,$header);
if ($sending)
{
echo "answer=success";
}
else
{
echo "answer=error";
}
?>
</body>
</html>
AS3 代码
sendbtn.addEventListener(MouseEvent.CLICK,trysend);
function trysend(e:MouseEvent):void{
if (subject.text == "") {
statustext.text = "give theme";
} else if (isValidEmail(from.text) != true) {
statustext.text = "give email.";
} else if (body.text == "") {
statustext.text = "write a message";
} else {
var variables:URLVariables = new URLVariables();
variables.theme = subject.text;
variables.email = from.text;
variables.msg = body.text;
var urlRequest:URLRequest = new URLRequest( "mail.php" );
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = variables;
var loader:URLLoader=new URLLoader();
loader.dataFormat=URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, showData);
loader.load(urlRequest);
}
}
function showData(evt:Event):void {
var loader:URLLoader=URLLoader(evt.target);
var resulting:URLVariables = new URLVariables(loader.data);
if (resulting.answer == "error") {
statustext.text = "Success!";
} else if (resulting.answer == "success"){
statustext.text = "error...";
subject.text="";
from.text="";
body.text="";
}
}
//Validation Email
function isValidEmail(email:String):Boolean {
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return emailExpression.test(email);
}
Contact form in flash with AS3 to PHP.
My problem is that the function "showdata" in AS3 does not take variables from the PHP code. It can't see the data=success from PHP, so i always get "error" even though the email was successfully sent.
Can you help me by suggesting what to change in function "showdata" or anything else functional?
I am testing on a online server
PHP code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$subject =$_POST[theme];
$message=$_POST[msg];
$mail_from=$_POST[email];
$header="from: $name <$mail_from>";
$to ='[email protected]';
$sending=mail($to,$subject,$message,$header);
if ($sending)
{
echo "answer=success";
}
else
{
echo "answer=error";
}
?>
</body>
</html>
AS3 code
sendbtn.addEventListener(MouseEvent.CLICK,trysend);
function trysend(e:MouseEvent):void{
if (subject.text == "") {
statustext.text = "give theme";
} else if (isValidEmail(from.text) != true) {
statustext.text = "give email.";
} else if (body.text == "") {
statustext.text = "write a message";
} else {
var variables:URLVariables = new URLVariables();
variables.theme = subject.text;
variables.email = from.text;
variables.msg = body.text;
var urlRequest:URLRequest = new URLRequest( "mail.php" );
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = variables;
var loader:URLLoader=new URLLoader();
loader.dataFormat=URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, showData);
loader.load(urlRequest);
}
}
function showData(evt:Event):void {
var loader:URLLoader=URLLoader(evt.target);
var resulting:URLVariables = new URLVariables(loader.data);
if (resulting.answer == "error") {
statustext.text = "Success!";
} else if (resulting.answer == "success"){
statustext.text = "error...";
subject.text="";
from.text="";
body.text="";
}
}
//Validation Email
function isValidEmail(email:String):Boolean {
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return emailExpression.test(email);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
loader.data
必须包含 PHP 代码回显的字符串。您必须将其放入URLVariables
中才能对其进行解析。顺便说一下,将加载器设置为成员变量,并且不要在函数内编写函数;)
loader.data
must contain the string echoed by your PHP code. You have to put it in aURLVariables
in order to have it parsed.And by the way, set your loader as a member variable and don't write function inside functions ;)
它现在的工作方式如下:
PHP(不要将其放在“html”“head”“body”标签中。仅使用此代码创建一个文件:)
ActionScript3 :
it works now like this:
PHP (dont put it in 'html' 'head' 'body' tags. Create a file only with this code: )
ActionScript3: