Flash 中的联系表单:AS3 检查 php 是否发送了电子邮件*问题*

发布于 2024-10-30 20:50:16 字数 2616 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪痕残 2024-11-06 20:50:16

loader.data 必须包含 PHP 代码回显的字符串。您必须将其放入 URLVariables 中才能对其进行解析。

function showData(evt:Event):void {
    var result:URLVariables = new URLVariables(loader.data);
    if (result.data == "success") {
    ...

顺便说一下,将加载器设置为成员变量,并且不要在函数内编写函数;)

loader.data must contain the string echoed by your PHP code. You have to put it in a URLVariables in order to have it parsed.

function showData(evt:Event):void {
    var result:URLVariables = new URLVariables(loader.data);
    if (result.data == "success") {
    ...

And by the way, set your loader as a member variable and don't write function inside functions ;)

春夜浅 2024-11-06 20:50:16

它现在的工作方式如下:

PHP(不要将其放在“html”“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){      
    print 'response=success';}
?>

ActionScript3

    function trysend(e:MouseEvent):void{
    Theme = subject.text;
    Email = from.text;
    Message = body.text;

    if (Theme == "") {
        statustext.text = "give a theme";
    } else if (Email == "") != true) {
        statustext.text = "give an email.";
    } else if (Message == "") {
        statustext.text = "give a message";
    } else {

        var variables:URLVariables = new URLVariables();
        variables.theme = Theme;
        variables.email = Email;
        variables.msg = Message;

        var urlRequest:URLRequest = new URLRequest("mail.php");
        urlRequest.method  = URLRequestMethod.POST;
        urlRequest.data = variables;

        var loader:URLLoader = new URLLoader();
        loader.load(urlRequest);
        loader.addEventListener(Event.COMPLETE, showData);
    }
}


    function showData(evt:Event):void {
        var Result:URLVariables = new URLVariables(evt.target.data);
        if (Result.response == "success") {
            statustext.text = "Success!";
            subject.text="";
            from.text="";
            body.text="";
        } else {
            statustext.text = "error";
        }
    }

it works now like this:

PHP (dont put it in 'html' 'head' 'body' tags. Create a file only with this code: )

<?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){      
    print 'response=success';}
?>

ActionScript3:

    function trysend(e:MouseEvent):void{
    Theme = subject.text;
    Email = from.text;
    Message = body.text;

    if (Theme == "") {
        statustext.text = "give a theme";
    } else if (Email == "") != true) {
        statustext.text = "give an email.";
    } else if (Message == "") {
        statustext.text = "give a message";
    } else {

        var variables:URLVariables = new URLVariables();
        variables.theme = Theme;
        variables.email = Email;
        variables.msg = Message;

        var urlRequest:URLRequest = new URLRequest("mail.php");
        urlRequest.method  = URLRequestMethod.POST;
        urlRequest.data = variables;

        var loader:URLLoader = new URLLoader();
        loader.load(urlRequest);
        loader.addEventListener(Event.COMPLETE, showData);
    }
}


    function showData(evt:Event):void {
        var Result:URLVariables = new URLVariables(evt.target.data);
        if (Result.response == "success") {
            statustext.text = "Success!";
            subject.text="";
            from.text="";
            body.text="";
        } else {
            statustext.text = "error";
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文