1

我已经做了好几天了,而且我已经拔掉了很多头发,现在我的头上只剩下一根头发了。那头发是我最后的骄傲。但说真的,我找到了几十个答案,但似乎没有一个适用于我的问题

我有一个我制作的网站的电子邮件表格。网站和表单是用 Flash (AS3) 制作的,处理电子邮件的脚本是一个外部 php 文件。电子邮件表单工作得很好,除了当我使用某些字符时:

  • %未显示在电子邮件中,包括其后面的任何文本
  • 当存在&, <or时>,表格会显示“正在发送.. ”,但不会超出该点;我没有收到任何电子邮件。
  • 所有(或至少)其他字符,如 !@#$^*_+-=~` 都没有问题。

我已经确定 AS3 和 php 代码都有

  • "MIME-Version: 1.0; Content-Type: text/html; charset=utf-8"if包含在我的 php 文件中的发送检查中;

  • AS3 中的文本字段设置为htmlText而不是仅text.


我的脚本:

邮件.php

    if( $yourName == true ) {
        $sender = $fromEmail;
        $yourEmail = "myemail@example.com"; // Here i of course use my own email address
        $ipAddress = $_SERVER['REMOTE_ADDR']; // This gets the user's ip Address

        $emailMsg = "Van: $sender\r\n" . 
                    "Name: $yourName\r" .
                    "Subject: $yourSubject\n\n" .
                    "$yourMsg\n\n\n\n" .
                    "------------------------------\r" .
                    "Sent from IP-address $ipAddress\r" .
                    "X-Mailer: PHP/" . phpversion();
       # these are three (out of many) things I tried to work around the problem #          
        //$emailMsg = str_replace( '&', "&amp;", $emailMsg );
        //$emailMsg = htmlspecialchars($emailMsg, ENT_QUOTES);
        //$emailMsg = mysql_real_escape_string($emailMsg);

        $return = "From: $sender\r\n";

        if( mail($yourEmail, "$yourSubject", $emailMsg, $return, "MIME-Version: 1.0; Content-Type: text/html; charset=utf-8")) { 
            echo "sentStatus=yes";
        }
        else {
            echo "sentStatus=no";
        }
    }
?>

FormScript.as

package  {
    /*required imports*/

public class FormScript extends Sprite {
    /*here are the variable declarations*/

    public function FormScript() {
        sendbtn.buttonMode = true;
        sendbtn.addEventListener(MouseEvent.CLICK, submit);
        resetbtn.buttonMode = true;
        resetbtn.addEventListener(MouseEvent.CLICK, reset);
        urlRequest.method = URLRequestMethod.POST;

        /*here are are some positionings and addchilds*/

        function init():void {
             //Set all fields to empty
             yourName.htmlText = "";
             fromEmail.htmlText = "";
             yourSubject.htmlText = "";
             yourMsg.htmlText = "";
             valid.text = "";
        }

        function submit(e:MouseEvent):void {                

        //Check to see if any of the fields are empty
            if(yourName.htmlText == "" || fromEmail.htmlText == "" ||
                yourSubject.htmlText == "" ||yourMsg.htmlText == "" ) {
                valid.text = "All fields must be filled in";
            }//Check if you're using a valid email address

            else if(!checkEmail(fromEmail.htmlText)) {
                valid.text = "Please enter a valid e-mail address";
            } 

            else { 
                valid.text = "Sending..";

                var emailData:String = 
                "name=" + yourName.htmlText +
                "&from=" + fromEmail.htmlText +
                "&subject=" + yourSubject.htmlText +
                "&msg=" + yourMsg.htmlText;

                var urlVars:URLVariables = new URLVariables(emailData);
                urlVars.dataFormat = URLLoaderDataFormat.TEXT;
                urlRequest.data = urlVars; varLoad.load( urlRequest );
                varLoad.addEventListener(Event.COMPLETE, thankYou );
            }
        }
        function reset(e:MouseEvent):void {
            init(); //call the initial clear function
        }
        function checkEmail(s:String):Boolean {
            //yourMsg.text = escape("&");

            //This tests for correct email address
            var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
            var r:Object = p.exec(s);
            if( r == null ) {
                return false;
            }
            return true;
        }

        function thankYou(e:Event):void { 
            var loader:URLLoader = URLLoader(e.target); 
            var sent = new URLVariables(loader.data).sentStatus;
            //valid.text = sent;
            if( sent == "yes" ) {
                valid.text = "Thank you for your e-mail!"; timer = new Timer(500);
                timer.addEventListener(TimerEvent.TIMER, msgSent);
                timer.start();
            }
            else {
                valid.text = "Something went wrong, please try again";
            }
        }

        function msgSent(te:TimerEvent):void {
            if(timer.currentCount >= 10) {
                init();
                timer.removeEventListener(TimerEvent.TIMER, msgSent);
            }
        }
    }
}
}

关键字:& 特殊字符符号小于小于大于大于 请不要编辑此问题,因为您无法搜索“&”等,因此其他人会找到此问题。

4

3 回答 3

1

在 Flash 中,需要对值进行编码,否则查询字符串可能会损坏。

var emailData:String = 
            "name=" + encodeURI(yourName.htmlText) +
            "&from=" + encodeURI(fromEmail.htmlText) +
            "&subject=" + encodeURI(yourSubject.htmlText) +
            "&msg=" + encodeURI(yourMsg.htmlText);
于 2012-06-13T13:50:47.020 回答
1

这里最明显的罪魁祸首是您创建 emailData 字符串的混乱方式。作为第一步,我建议将其重新格式化为以下内容:

var urlVars:URLVariables = new URLVariables();
urlVars.name = yourName.htmlText;
urlVars.from = fromEmail.htmlText;
urlVars.subject = yourSubject.htmlText;
urlVars.msg = yourMsg.htmlText;

我认为这会自动对值进行 URI 编码,但如果没有,请按照 Mark Knol 的建议使用 encodeURI()。

于 2012-06-13T13:53:14.040 回答
0

尝试使用

$emailMsg = utf8_decode($emailMsg);

我解码从 Flash 获得的所有字符串。

如果这没有帮助,请使用

$emailMsg = urldecode($emailMsg);

或两者兼而有之:D

于 2012-06-13T13:45:51.497 回答