+ Reply to Thread
Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: AS3 / PHP email form HELP

  1. #1
    phils13776 is offline x10Hosting Member phils13776 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    18

    AS3 / PHP email form HELP

    Hello all,

    Im having problems setting up an email form using action script 3 and php. I have tried numerous variation of forms with no luck. The form is up on the site. It confirms that the message was sent. However i never get a message on my hosted email. PLZ HELP!



    HERE IS THE ACTION SCRIPT
    (sample that Im using):


    // Set text formatting colors for errors, waiting..., and success mechanisms
    var errorsFormat:TextFormat = new TextFormat();
    errorsFormat.color = 0xFF0000;

    var waitingFormat:TextFormat = new TextFormat();
    waitingFormat.color = 0x339900;

    var successFormat:TextFormat = new TextFormat();
    successFormat.color = 0x3366FF;

    // hide the little processing movieclip
    processing_mc.visible = false;

    // Assign a variable name for our URLVariables object
    var variables:URLVariables = new URLVariables();

    // Build the varSend variable
    var varSend:URLRequest = new URLRequest("http://www.lavidapictures.com/contact_parse.php");
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;

    // Build the varLoader variable
    var varLoader:URLLoader = new URLLoader;
    varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader.addEventListener(Event.COMPLETE, completeHandler);


    // Handler for PHP script completion and return
    function completeHandler(event:Event):void{
    // remove processing movieclip
    processing_mc.visible = false;
    // Clear the form fields
    name_txt.text = "";
    email_txt.text = "";
    msg_txt.text = "";
    // Load the response from the PHP file
    status_txt.text = event.target.data.return_msg;
    status_txt.setTextFormat(successFormat);
    }

    // Add an event listener for the submit button and what function to run
    submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

    // Validate form fields and send the variables when submit button is clicked
    function ValidateAndSend(event:MouseEvent):void{

    //validate form fields
    if(!name_txt.length) {
    status_txt.text = "Please enter your name.";
    status_txt.setTextFormat(errorsFormat);
    } else if(!email_txt.length) {
    status_txt.text = "Please enter an email address";
    status_txt.setTextFormat(errorsFormat);
    } else if(!validateEmail(email_txt.text)) {
    status_txt.text = "Please enter a VALID email address";
    status_txt.setTextFormat(errorsFormat);
    } else if(!msg_txt.length) {
    status_txt.text = "Please enter a message.";
    status_txt.setTextFormat(errorsFormat);
    } else {

    // All is good so send the message to the parse file
    // Show the little "processing_mc" movieclip
    processing_mc.visible = true;

    // Ready the variables for sending
    variables.userName = name_txt.text;
    variables.userEmail = email_txt.text;
    variables.userMsg = msg_txt.text;

    // Send the data to the php file
    varLoader.load(varSend);

    // Put a temporary message in the response field while the PHP file sends back
    // If the code does not connect to the PHP file this message will remain visible to user
    status_txt.text = "Waiting for server connection...";
    status_txt.setTextFormat(waitingFormat);

    } // close else after form validation

    } // Close ValidateAndSend function //////////////////////////////////////////////////////////////


    // Validate email function
    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;
    }
    ////////////////////////////////////


    HERE IS THE PHP SCRIPT:

    <?
    // Create local variables from the Flash ActionScript posted variables
    $senderName = $_POST['userName'];
    $senderEmail = $_POST['userEmail'];
    $senderMessage = $_POST['userMsg'];

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

    // IMPORTANT - Change these lines to be appropriate for your needs - IMPORTANT

    $to = "bryan@lavidapictures.com";
    $from = "$senderEmail";
    $subject = "Contact from your site";

    // Modify the Body of the message however you like
    $message = "Message from your website:

    Their Name: $senderName
    Their Email: $senderEmail
    Their Message is below: $senderMessage";

    // Build $headers Variable

    $headers = "From: $from\r\n";
    $headers .= "Content-type: text\r\n";
    $to = "$to";
    // Send the email
    mail($to, $subject, $message, $headers);

    // Assemble the message that goes back to Flash
    // The flash ActionScript is looking for a return variable of "return_msg"
    $my_msg = "Thanks $senderName, your message has been sent.";
    // Print the data back to flash who is patiently waiting for it in the onCompleteHandler
    print "return_msg=$my_msg";
    // Exit script
    exit();
    ?>

  2. #2
    bidzey75's Avatar
    bidzey75 is offline x10Hosting Member bidzey75 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    51

    Re: AS3 / PHP email form HELP

    have you seen this script work somewhere? I find AS3 a bit different than what I'm used to seeing.

    here is what you got:
    Code:
    / Build the varSend variable
    var varSend:URLRequest = new URLRequest("http://www.lavidapictures.com/contact_parse.php");
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;
    
    // Build the varLoader variable
    var varLoader:URLLoader = new URLLoader;
    varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
    I would expect something more like this: (also you should access your php script not using http protocol but access it locally)
    Code:
    var loader:URLLoader = new URLLoader();
    var req:URLRequest = new URLRequest("http://www.lavidapictures.com/contact_parse.php");
    var variables:URLVariables = new URLVariables();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    req.method = URLRequestMethod.POST;

    here is 1 ready made for ya


    Also, maybe the problem is not the AS3, if your sure that php parser was actually called, then you should get an email because that parser works on it's own. If any data was not carried over from flash it would still send you the email. You may not get the content you expected in the email, but if that parser ran you would get an email.

    The only thing I might see that parser not sending the email is if the header is empty. I'm not sure what happens then. So try this:

    change:
    Code:
    $from = "$senderEmail";
    to something static like this:
    Code:
    $from = "bryan@lavidapictures.com";
    then run the script directly, you wont get content inside the email but you should get an email. If you don't, maybe the issue is somewhere else.
    Last edited by bidzey75; 05-11-2011 at 07:42 PM.

  3. #3
    phils13776 is offline x10Hosting Member phils13776 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    18

    Re: AS3 / PHP email form HELP

    Thanks for the response. I will try what you mentioned. BTW i looked that link before. The source link is broken. I believe i tried that script with no luck. I tried 4 diff ones.

  4. #4
    bidzey75's Avatar
    bidzey75 is offline x10Hosting Member bidzey75 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    51

    Re: AS3 / PHP email form HELP

    i downloaded it and it works fine for me, you just have to open the "contact_form.php" file and make changes to line #17, 25, and 26 replacing the website name and email address.

    Dont forget to grab the :
    1 - "js" folder
    2- the code inside the "index.html" file and put it in your own page
    3- "contact_form.swf" file
    4 - "contact_form.php"

    all this have to be in the same folder on your website. (you will find all this in the "deploy" folder inside the zip file.)
    I attached the file if your having problems downloading it.
    Attached Files
    Last edited by bidzey75; 05-11-2011 at 08:31 PM.

  5. #5
    phils13776 is offline x10Hosting Member phils13776 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    18

    Re: AS3 / PHP email form HELP

    i tried the code below and now the php is not being called and there is no confirmation.
    http://www.lavidapictures.com/

    I will attempt to use the one you provided next and let you know.

    I have a feeling its something with x10. Maybe i have to change something. I setup the email account through cpanel. Maybe there settings i need to change. The mailbox works as i can send and receive from my email client (from/to bryan@lavidapictures.com).



    NEW CODE PHP:

    <?

    var loader:URLLoader = new URLLoader();
    var req:URLRequest = new URLRequest("contact_parse.php");
    var variables:URLVariables = new URLVariables();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    req.method = URLRequestMethod.POST;


    $senderName = $_POST['userName'];
    $senderEmail = $_POST['userEmail'];
    $senderMessage = $_POST['userMsg'];

    // Strip slashes on the Local variables for security

    $senderName = stripslashes($senderName);
    $senderEmail = stripslashes($senderEmail);
    $senderMessage = stripslashes($senderMessage);


    $to = "bryan@lavidapictures.com";
    $from = "bryan@lavidapictures.com";
    $subject = "Contact from your site";
    // Modify the Body of the message however you like
    $message = "Message from your website:

    Their Name: $senderName
    Their Email: $senderEmail
    Their Message is below: $senderMessage";


    $headers = "From: $from\r\n";
    $headers .= "Content-type: text\r\n";
    $to = "$to";

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


    $my_msg = "Thanks $senderName, your message has been sent.";

    print "return_msg=$my_msg";

    exit();
    ?>

  6. #6
    bidzey75's Avatar
    bidzey75 is offline x10Hosting Member bidzey75 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    51

    Re: AS3 / PHP email form HELP

    Quote Originally Posted by phils13776 View Post
    $to = "$to";
    don't assign the "$to" variable a second time, just erase that line above.

    when you run this script directly you may not get feed back and just a white page. if you want feedback for sure when you run it directly replace
    Code:
    mail($to, $subject, $message, $headers);
    with
    Code:
    if(mail($to, $subject, $message, $headers)){
    echo "email sent";
    }else{
    echo "email not sent";
    }
    keep a copy of the original in case you want to use it, then again it's all written here in this forum anyways... If you follow the instructions with the zip file you'll be able to scrap all this.

  7. #7
    phils13776 is offline x10Hosting Member phils13776 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    18

    Re: AS3 / PHP email form HELP

    Alright I had tried then one you supplied. I just did it again just in case. It gets a server error.
    see here www.lavidapictures.com.

    I uploaded all the files including the js folder/file. The php script is posted below.

    this is frustrating. I never had so much trouble with anything.


    <?php
    if(empty($_POST['senderEmail'])){
    echo"Error: No email address found";
    exit;
    }
    $senderName = $_POST['senderName'];
    $senderEmail = $_POST['senderEmail'];
    $senderMessage = nl2br($_POST['senderMessage']);
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";


    $headers .= "From: bryan@lavidapictures.com <> \n";
    $headers .= "Reply-To: " . $senderEmail . "\n\n";

    $siteName = "lavidapictures.com";
    $to = "bryan@lavidapictures.com ";

    $toSubject = "Message from $senderName via $siteName";
    $emailBody = "From: $senderName <br />
    Email: $senderEmail <br /> <br />
    Message: <br />
    $senderMessage
    <br />";
    $message = $emailBody;
    $ok = mail($to, $toSubject, $message, $headers);
    if($ok){
    echo "returnValue=1";
    }else{
    echo "returnValue=0";
    }
    ?>

  8. #8
    bidzey75's Avatar
    bidzey75 is offline x10Hosting Member bidzey75 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    51

    Re: AS3 / PHP email form HELP

    let see fisrt if your mail function works... create a new php file and put this in it
    Code:
    <?php
    $headers = "From: bryan@lavidapictures.com\r\n";
    if(mail("bryan@lavidapictures.com", "this is my subject", "this is my message", $headers)){
    echo "email sent";
    }else{
    echo "email not sent";
    }
    ?>
    then run the script and check you mail.

    also...
    I see your sending the email in text/html format, if I remember correctly someone on here said that the php mail function only work for text version, (Content-Type: text/plain) no html. I would check on that. If so, that probably the server error your getting. If you have access to your error logs file in your Cpanel check what it's telling you about the error.
    Last edited by bidzey75; 05-11-2011 at 09:36 PM.

  9. #9
    phils13776 is offline x10Hosting Member phils13776 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    18

    Re: AS3 / PHP email form HELP

    No sure if I "ran" it correctly. I created new php file(with your script) uploaded it. Then I accessed it at:
    www.lavidapictures.com/test.php The response was email not sent.

    Its strange if the previous files worked on your site; why not mine.

  10. #10
    bidzey75's Avatar
    bidzey75 is offline x10Hosting Member bidzey75 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    51

    Re: AS3 / PHP email form HELP

    Quote Originally Posted by phils13776 View Post
    Its strange if the previous files worked on your site; why not mine.
    I'll try it on the x10 server later, I'm about to leave for work. I had tried it on my personal site could be a different story.

    if that simple mail function (test.php) did not work that's a problem, and you'll have to take that up with X10, that's as simple as it gets. Probably the problem to all your problems.

    ---------- Post added at 10:40 AM ---------- Previous post was at 06:55 AM ----------

    I can confirm that the problem doesn't envolve the code in the zip file. It works fine on my site, but I get the same "server error" when i uploaded it to my free X10 account. Don't break your head with the code, it's a server configuration somewhere. If you can check the error log file it might be logged in there. I would go but I can't access my cpanel from work. We're behind a proxy and it won't let me go to my cpanel from my work station.

    this one won't work, and I tried various versions, like changing the "$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";" to "Content-type: text/plain;" to no success.
    http://bidzey.x10.mx/deploy/

    this is the identical code running here successfully, and it's set to send you the message, I will be deleting this page on your request, or no later than tonight before I go to bed if I don't hear from you. I sent you an email using it, and it said "sent successfully" check you email as soon as you read this.
    ( URL AS BEEN DELETED )


    so once you figured out why you get a server error and fix it, just follow the instruction in the post where the zip file is attached and your problems will be over.
    look at post #19 here, and try that first
    Last edited by bidzey75; 05-12-2011 at 01:57 PM.

+ Reply to Thread
Page 1 of 4 123 ... LastLast

Similar Threads

  1. Form email
    By sonyaseth90 in forum Free Hosting
    Replies: 0
    Last Post: 12-22-2010, 07:43 AM
  2. Email form
    By jaygreenly in forum Free Hosting
    Replies: 9
    Last Post: 12-13-2009, 03:35 PM
  3. email form
    By death180 in forum Programming Help
    Replies: 8
    Last Post: 09-17-2009, 09:58 AM
  4. PHP Email Form
    By DeadBattery in forum Programming Help
    Replies: 4
    Last Post: 04-01-2008, 05:32 AM
  5. RE: email form
    By gwuapo2007 in forum The Marketplace
    Replies: 6
    Last Post: 11-13-2007, 06:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers