A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: Problem with contact form

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    13

    Problem with contact form

    Hello,
    I'm devolping a web in Flash.
    But I'm having problem.
    When I put cntrl+enter in flash and I fill the data it works, and send the mail.
    But when i upload it to my webserver, it doesn't send anything.
    The code I'm using in Flash is:
    stop();

    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    // ----------------------------------------------------------------
    var variables:URLVariables = new URLVariables();
    // Be sure to change this URL to the PHP parse file on your site server
    var varSend:URLRequest = new URLRequest("MYWEBSITE/contact_parse.php");
    var varLoader:URLLoader = new URLLoader;
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;

    status_txt.text = "";

    submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

    function ValidateAndSend(event:MouseEvent):void{

    //validate form fields
    if(!name_txt.length) {
    status_txt.text = "Por favor introduzca su nombre.";
    } else if(!email_txt.length) {
    status_txt.text = "Por favor introduzca su correo";
    } else if(!validateEmail(email_txt.text)) {
    status_txt.text = "Por favor introduzca un correo valido";
    } else if(!subject_txt.length) {
    status_txt.text = "Por favor introduzca el asunto";
    } else if(!msg_txt.length) {
    status_txt.text = "Por favor introduzca su mensaje";

    } else {

    status_txt.text = "Gracias " + name_txt.text + ", su mensaje se ha enviado.";

    variables.userName = name_txt.text;
    variables.userEmail = email_txt.text;
    variables.userSubject = subject_txt.text;
    variables.userMsg = msg_txt.text;

    varLoader.load(varSend);

    gotoAndStop(2);

    }
    }

    function validateEmail(str:String):Boolean {
    var pattern:RegExp = /(\w|[_.\-])+((\w|-)+\.)+\w{2,4}+/;
    var result:Object = pattern.exec(str);
    if(result == null) {
    return false;
    }
    return true;
    }

    The PHP:
    <?php
    /*
    --- Created By Adam @ www.developphp.com ---
    --- For help or script expansion join our forums there ---
    --- Use this code as your own any way you like ---
    */
    // Create local PHP variables from the info the user gave in the Flash form
    $senderName = $_POST['userName'];
    $senderEmail = $_POST['userEmail'];
    $senderMessage = $_POST['userMsg'];
    $senderSubject = $_POST['userSubject'];

    // Strip slashes on the Local variables
    $senderName = stripslashes($senderName);
    $senderEmail = stripslashes($senderEmail);
    $senderMessage = stripslashes($senderMessage);
    $senderSubject = stripslashes($senderSubject);

    //!!!!!!!!!!!!!!!!!!!!!!!!! change this to your email !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    $to = "myEMAIL";
    // Place sender Email address here
    $from = "$senderEmail ";
    $subject = "$senderSubject";
    //Begin HTML Email Message
    $message = <<<EOF
    <html>
    <body bgcolor="#FFFFFF">
    <b>Nombre</b> = $senderName<br /><br />
    <b>Correo</b> = <a href="mailto:$senderEmail">$senderEmail</a><br /><br />
    <b>Mensaje</b> = $senderMessage<br />
    </body>
    </html>
    EOF;
    //end of message
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $to = "$to";

    mail($to, $subject, $message, $headers);

    exit();
    ?>

    Hope you can help me out, I'm kind of out of ideas and desperate.
    THanks!
    Cheers!

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    Do you have the flash debugger installed in your browser? If so what errors does it report when you try to send the mail? Are you callining the PHP file from a diffrent domain than the one your .swf lives in?
    ~calmchess~

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Do you have the flash debugger installed in your browser? No, is it necesary? Do you recomend me to, I'm just having that problem.
    If so what errors does it report when you try to send the mail?
    Are you callining the PHP file from a diffrent domain than the one your .swf lives in? No. The strange thing is that when I run the file from Flash it sends the mail, but when I do it from a webserver it doesn't (also, for example if I publish it with cntrl+enter it sends, but if I put F12 it doesn't)
    THanks!

  4. #4
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    If you plan to build Flas applications then yes the debugger is necessary do a google search for flashplayer debugger get the one for IE test your application and tell me what errors your receive.
    ~calmchess~

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation:

  6. #6
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    you need a cross domain policy file. there plenty of examples on google and its not real hard to setup but will require you to do some reading.
    ~calmchess~

  7. #7
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    also look up Security in the AS 3.0 livedocs you might need to add some code to your loader
    ~calmchess~

  8. #8
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks, mate.
    I appreciate your help. It work out in a trial server I had, I put:

    <?xml version="1.0"?>

    <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

    <cross-domain-policy>

    <allow-access-from domain="*.site.com" secure="false" />

    <allow-access-from domain="word.abcfamily.com" secure="false" />
    <allow-access-from domain="*.site.com/*" secure="false" />

    <allow-access-from domain="word.abcfamily.com/*" secure="false" />

    </cross-domain-policy>

    "word" was substituted by the subdomain.
    the problem is that once I put it in the real server, it didn't work. Same problem.
    Don't know what to do.
    I tried plenty of stuff, for example
    <allow-access-from domain="*" secure="false" />
    <allow-access-from domain="*"/>
    <allow-access-from domain="domain.com" secure="false" />
    etc,etc,etc...

    I will really appreciate your help.
    Thanks!!

  9. #9
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    You probably just need to use a relative URL rather than
    var varSend:URLRequest = new URLRequest("MYWEBSITE/contact_parse.php");

    var varSend:URLRequest = new URLRequest("contact_parse.php");

  10. #10
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Oh and if you don't want your site to end up being used to send out spam I suggest you not use this PHP code... It is very bad!

    Please read this:
    http://www.stevedawson.com/article0015.php

  11. #11
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks, mate for the help. anyhow I can't get my problem solved. Maybe there are problem with the hosting company, I'll give them a call (anyhow you comment help me out in my trial subdomain, so I don't need anymore the crossdomain)
    Thanks!

  12. #12
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    One think is a problem, is that is I enter mydomain.com/bla.php it sends me a blank email, so the php works, but not every time I enter data in my web it send me a mail... why can that be? THanks!

  13. #13
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Guys, this is kind of urgent, and I will really appreciate your help:
    The site is currently online, but their server don't have the port 25 open (I think), so I will reedirect the contact form to my site until they solve that problem. The problem is that when I do that, I found the same original problem:

    Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://www.site.com/file.swf cannot load data from http://subdomain.mydomain.com/file.php
    at file_fla::contact_30/frame1()

    Why is that happening?!?!?!
    THANKS!

  14. #14
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    well you don't have http://www............you just have http://subdomain.......so maybe you aren't pointing at the correct domain since u aren't using www......do you have any control over the DNS for your domain?
    ~calmchess~

  15. #15
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    I have tried that, and no success. The same error. And no, unfortunatly I don't have control over the DNS.
    Cheers!

  16. #16
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    I have literally add the web that the error gaves me that can't access to the crossdomain and still can't succed.
    Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://page.com/file.swf cannot load data from http://www.subdomain.myweb.com/file.php.
    at file_fla::contact_30/frame1()
    I literally add:
    http://www.subdomain.myweb.com/file.php to my crossdomain and no sucess...
    I'll appreciate your help. Thanks!

  17. #17
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    here is a cross domain policy file known to work by me Please change the URLs I don't care if you use them really it would just give me access to your domain

    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy SYSTEM"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="calmchess.com" />
    <allow-access-from domain="www.calmchess.com" />
    </cross-domain-policy>
    ~calmchess~

  18. #18
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    PS port 21 and 25 should be open by your webhost especially if they are allowing PHP they don't generally close mail services or database services and if you call them they will gladly open up whatever you want .......I use Flash media server and They have been known to install it and open port 1935 and 1111 ...Also are you using PHP pear to send mail or the actual mail settings within php.ini because usually you have to have your own mail server in order to use php.ini settings and even then its tricky. I don't remember all the details for the php.ini method but just saying this for your information.
    ~calmchess~

  19. #19
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    While I'm at it I'll check to see if Security context is required on the loader within flash I can't remember off the top of my head.......I mentioned this before did you ever look up SECURITY in the live docs? Sometimes you have to tell the loader that the crossdomain policy file is out there not usually though.
    ~calmchess~

  20. #20
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    I just looked and I don't need security Context on my loaders that are just calling a PHP file or just loading text or XML I think if I remember correctly its more for loaders that load Images. Look it up in the livedocs though Its been months since I delt with it.
    ~calmchess~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center