1

私は何日もこれを続けてきましたが、非常に多くの毛を抜いたので、今では頭に1本の毛しか残っていません. その髪は私の最後の誇りです。しかし、真剣に、私は何十もの答えを見つけましたが、どれも私の問題に当てはまらないようです!

作成した Web サイトの電子メール フォームがあります。サイトとフォームは Flash (AS3) で作成され、電子メールを処理するためのスクリプトは外部の php ファイルです。特定の文字を使用する場合を除いて、電子メール フォームは正常に機能します。

  • %その直後のテキストを含め、電子メールには表示されません
  • 、またはが存在する場合&、フォームは「送信中..」と表示されますが、そのポイントを超えることはありません。メールが届きません。<>
  • !@#$^*_+-=~` のようなすべての (または少なくともほとんどの) 他の文字は問題ありません。

AS3 と php コードの両方が

  • "MIME-Version: 1.0; Content-Type: text/html; charset=utf-8"php ファイルの送信ifチェックに含まれています。

  • 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

ここで最も明らかな原因は、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 に答える
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 に答える
0

使ってみて

$emailMsg = utf8_decode($emailMsg);

Flash から取得したすべての文字列をデコードします。

これで問題が解決しない場合は、

$emailMsg = urldecode($emailMsg);

または両方:D

于 2012-06-13T13:45:51.497 に答える