Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple Flash and PHP form

Options
  • 21-11-2006 1:48pm
    #1
    Registered Users Posts: 123 ✭✭


    Hi,

    I'm working on a website that has a simple contact from with Name, Email, Tel and message fields.

    I have setup the form and given all the text box's variable names, I have a submit button that gathers the variables and posts them to an email PHP file so that the info can be emailed to a specified email address.

    For some reason I don't seem to be receiving any test emails that I have sent, I'm new to PHP so please bare with me.

    I tested the flash file by changing POST to GET, this displayed all the variables and what was contained in them when I debug, which would indicate flash frontend is working.

    The server that the site is on says it supports PHP 5.

    Here's the PHP code I used

    <?PHP

    $sendTo = "me@there.com";
    $subject = "Contact Request";
    $headers = "From: " . $_POST["first_name"] ." ". $_POST["last_name"] . "<" . $_POST["email"] .">\r\n";
    $headers = "Message: " . $_POST["message"]
    $headers .= "Reply-To: " . $_POST["email"] . "\r\n";
    $headers .= "Return-path: " . $_POST["email"];
    $message = $_POST["message"];
    mail($sendTo, $subject, $message, $headers);

    ?>


    Any Help would be much appreciated.


Comments

  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    Clone wrote:
    The server that the site is on says it supports PHP 5.
    Maybe your host has disabled the mail() function to avoid being used as a spam source.

    If that's not the case, you should step back a bit and simplify things.
    1) Write a script that just sends you a simple email. Don't involve the Flash movie.
    [PHP]mail( 'me@there.com', 'Super basic test', 'This is the body of the super basic test' );[/PHP] Note that I omitted the optional headers parameter. If that works, it might indicate that your headers parameter is wrong.
    2) Change the script to display what it receives from the Flash movie. You can tell Flash to POST the data. In this case you won't call mail().

    See comments and examples at php.net mail() documentation.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    The second line of headers for a start... No '.' and no ';'


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Here you are:

    [php]
    if(!$_POST) die("You did not enter a name, please go back and update this");
    if(!$_POST) die("You did not enter an email address, please go back and update this");

    $sendTo = "me@there.com";
    $subject = "Contact Request";
    $headers = "From: " . $_POST["first_name"] ." ". $_POST["last_name"] . "<" . $_POST["email"] .">\r\n";
    $headers.= "Message: " . $_POST["message"];
    $headers.= "Reply-To: " . $_POST["email"] . "\r\n";
    $headers.= "Return-path: " . $_POST["email"];
    $message = $_POST["message"];

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

    echo "The email has been sent.";

    die();
    [/php]


  • Registered Users Posts: 123 ✭✭Clone


    Thanks! for the replies.

    After playing with the code and confirming with the ISP that they do support the mail() function, I was still getting no success.

    I thought to myself if the simple script wasn't working there had to be an explanation, I had the idea that the spam filter on the email address i had specified was blocking the mails getting through, I checked this and found nothing, but decided to change the email address to gmail and then as if by magic it all worked including the info out of flash!!

    Hooray, hours of banging my head off the wall and as per usual it's something simple.

    Thanks again for your replies they have been very helpful.


  • Registered Users Posts: 123 ✭✭Clone


    Just one more question, I left out that I have a telephone number field aswell, just wondering how I'd add that to the PHP?

    would I add the following to the end

    $phone = $_POST["tel"];

    mail($sendTo, $subject, $message, $phone, $headers);


  • Advertisement
  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    No, the phone number will have to be incorporated in to the message body or headers, the mail() function only allows for the four specific parameters.

    Please not the change to the second line of headers in your code, if you haven't implemented that then that part of the header is NOT being sent.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    //code originally by Mirror and added extras to it
    
    [COLOR=#007700]if(![/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'first_name'[/COLOR][COLOR=#007700]]) die([/COLOR][COLOR=#dd0000]"You did not enter a name, please go back and update this"[/COLOR][COLOR=#007700]);
            if(![/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'email'[/COLOR][COLOR=#007700]]) die([/COLOR][COLOR=#dd0000]"You did not enter an email address, please go back and update this"[/COLOR][COLOR=#007700]);
    
            [/COLOR][COLOR=#0000bb]$sendTo [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"me@there.com"[/COLOR][COLOR=#007700];
            [/COLOR][COLOR=#0000bb]$subject [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"Contact Request"[/COLOR][COLOR=#007700];
            [/COLOR][COLOR=#0000bb]$headers [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"From: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"first_name"[/COLOR][COLOR=#007700]] .[/COLOR][COLOR=#dd0000]" "[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"last_name"[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]" <" [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"email"[/COLOR][COLOR=#007700]] .[/COLOR][COLOR=#dd0000]">\r\n"[/COLOR][COLOR=#007700];[/COLOR][COLOR=#007700]
            [/COLOR][COLOR=#0000bb]$headers[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Reply-To: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"email"[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]"\r\n"[/COLOR][COLOR=#007700];
            [/COLOR][COLOR=#0000bb]$headers[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Return-path: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"email"[/COLOR][COLOR=#007700]];
            [/COLOR][COLOR=#0000bb]$message [/COLOR][COLOR=#007700]= @[/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"message"[/COLOR][COLOR=#007700]][COLOR=#007700] . "\r\n"[/COLOR]
    [COLOR=#007700]        [COLOR=#0000bb]$message[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Tel: " [/COLOR][COLOR=#007700]. @[/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"tel"[/COLOR][COLOR=#007700]] . "\r\n";[/COLOR]
    [/COLOR]
    [/COLOR][COLOR=#007700]    
            
            [/COLOR][COLOR=#0000bb]mail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$sendTo[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$message[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$headers[/COLOR][COLOR=#007700]);
    
    echo [/COLOR][COLOR=#dd0000]"The email has been sent."[/COLOR][COLOR=#007700];
    
    die();  
    
    [/COLOR][COLOR=#0000bb][/COLOR]
    
    Try this code and see if it's working better now.


  • Registered Users Posts: 123 ✭✭Clone


    Hi,

    I tried using the code you specified Louie to no avail, nothing happens at all.

    This is the script I'm using at the moment. it works perfect, Just need to get the phone or "tel" variable included in the mail.

    if(!$_POST) die("You did not enter a name, please go back and update this");
    if(!$_POST) die("You did not enter an email address, please go back and update this");


    $sendTo = "me@there.com";
    $subject = "Contact Request";
    $headers = "From: " . $_POST["first_name"] ." ". $_POST["last_name"] . "<" . $_POST["email"] .">\r\n";
    $headers.= "Message: " . $_POST["message"];
    $headers.= "Reply-To: " . $_POST["email"] . "\r\n";
    $headers.= "Return-path: " . $_POST["email"];
    $message = $_POST["message"];

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

    echo "The email has been sent.";

    die();


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    have you got a link where we can see this?
    Did you change the name of the tel field to match the code?


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Way ta steal there Louie!

    However he's right Clone, that code works so if it's not working for you, you've made an error somewhere else...


  • Advertisement
  • Closed Accounts Posts: 1,200 ✭✭✭louie


    Sorry man, not stealing cause is not my type. It was easier to copy your code and add the extras to it.
    I added your name above.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Lol I was kidding, but thanks anyway, gotta be credited for our masterpieces! ;)


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Ah your problem is that you havent sectioned off the code Clone. What you need to do is have the code you've been given here, and put it at the top of your script, with something like [php]if(isset($_POST)) { // <- a value assigned to the submit button.

    //insert mailing code here
    //insert mailing code here
    //insert mailing code here

    } // this curly bracket is very important, as is the one above.

    ?> //and then you close the php section

    //and here you insert your flash form, with the action directed to the page its on, and its method set to post
    [/php]


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    the form needs more work but that should do it.


  • Registered Users Posts: 123 ✭✭Clone


    Thanks again to you all for your additions,

    I'll try the code louie suggested again and make sure I've got everything set up correctly on the frontend, but I did make sure that the field in flash was "tel",

    when i filled in the form and submitted, no mail came through at all.

    I'll try it again and let you know how I get on


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Actually, Louie, what are the @ symols for in the messages part of your code? I haven't seen that before...


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    So you don't get a php error if the variable is not set.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Ah I see, cheers!


  • Registered Users Posts: 123 ✭✭Clone


    HI,

    I tried using this code:

    <?PHP
    if(!$_POST) die("You did not enter a name, please go back and update this");
    if(!$_POST) die("You did not enter an email address, please go back and update this");

    $sendTo = "me@there.com";
    $subject = "Contact Request";
    $headers = "From: " . $_POST["first_name"] ." ". $_POST["last_name"] . " <" . $_POST["email"] .">\r\n";
    $headers.= "Reply-To: " . $_POST["email"] . "\r\n";
    $headers.= "Return-path: " . $_POST["email"];
    $message = @$_POST[&quot;message"] . "\r\n"
    $message.= "Tel: " . @$_POST[&quot;tel"] . "\r\n";



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

    echo "The email has been sent.";

    die();



    ?>

    not working, I've checked the flash output the variable for the phone No. is "tel" It's outputting the variables.
    Am I right in thinking that I should have the curly brackets in where you've specified?


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    try this code and tell us the output that is written on the page:

    [php]
    $err_qs = "";
    foreach($HTTP_POST_VARS as $key=>$value){
    $err_qs = $key . "=" . $value . "&";
    echo $err_qs . "<br />";
    }
    [/php]


  • Advertisement
  • Registered Users Posts: 123 ✭✭Clone


    My form is in flash, so when It posts the variables to the email.php it then goes to a frame where I have "message sent" text, so it doesn't jump to a html page at all.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    I suggest you just post up the whole page Clone, no offence but you don't seem too experienced and it's probably something small you're missing.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    put the above code at the end of the email.php and then add die();
    [php]
    $err_qs = "";
    foreach($HTTP_POST_VARS as $key=>$value){
    $err_qs = $key . "=" . $value . "&";
    echo $err_qs . "<br />";
    }
    die();
    [/php]

    or add this code to end of the redirect url link

    your_redirect_page_name?<?php echo $err_qs;?>
    and use this code
    [php]
    $err_qs = "";
    foreach($HTTP_POST_VARS as $key=>$value){
    $err_qs .= $key . "=" . $value . "&";
    //echo $err_qs . "<br />";
    }
    //die();
    [/php]


  • Registered Users Posts: 123 ✭✭Clone


    yes your right, To be honest I'm new to PHP, this is my first attempt at it as you've discovered,

    I'll attach the php file, would you like to look a the fla too?, Although I'm 99.9% sure the variables are correctly named like all the other ones that work


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    try this page:
    [php]
    <?PHP
    $error = false;
    $error_msg = "";
    if(!isset($_POST)){
    $error = true;
    $error_msg .= ("<br />You did not enter a name, please go back and update this");
    }
    if(!isset($_POST)) {
    $error = true;
    $error_msg .= ("<br />You did not enter an email address, please go back and update this");
    }
    if(!$error && isset($_POST)){//we don't have an error so send message
    $sendTo = "me@there.com";
    $subject = "Contact Request";
    $headers = "From: " . addslashes($_POST["first_name"]) ." ". addslashes($_POST["last_name"]) . " <" . addslashes($_POST["email"]) .">\r\n";
    $headers.= "Reply-To: " . addslashes($_POST["email"]) . "\r\n";
    $headers.= "Return-path: " . $_POST["email"];
    $message = @$_POST[&quot;message"] . "\r\n";
    $message.= "Tel: " . @$_POST[&quot;tel"] . "\r\n";
    //now send email
    mail($sendTo, $subject, $message, $headers);

    echo "The email has been sent.";

    //die();
    }else{
    echo $error_msg;
    }
    ?>

    [/php]


  • Registered Users Posts: 123 ✭✭Clone


    Sorted!!,

    I've got everything working now as it should be, one of the original scripts I had with the dodgy email address works a treat. :D

    Thanks everybody for your help.

    Now on to my next issue and I should be done with this project.

    Anybody know about issues between flash player 8 and 9 maybe a new thread is needed.


Advertisement