Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    42
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Sending form data to email with PHP--having trouble!!!!

    I am trying to make a simple form for people to fill out, and I want the data entered in the form to be sent to my email address when users click the submit button. I have gotten to where I get an email, but the email is blank!! I have been working with this for about two weeks, trying to get it to work, and I am getting really frustrated.

    Here is the HTML code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Transitional//EN" "(show_form.html)">
    <html>
    <head>
    <title>E-Mail Form</title>
    </head>
    <body>

    <form method="post" action="do_sendform.php3">

    <p>Your Name:
    <br />
    <input type="text" name="sender_name" size=30>
    </p>

    <p>Your E-Mail Address:
    <br />
    <input type="text" name="sender_email" size=30>
    </p>

    <p>Message:
    <br />
    <textarea name="message" cols=30 rows=5></textarea>
    </p>

    <input type="submit" value="Send This Form">

    </form>

    </body>
    </html>

    and here is the PHP code:

    <?php_track_vars?>
    <?php

    $msg = "Sender Name:\t$sender_name\n";
    $msg .= "Sender E-Mail:\t$sender_email\n";
    $msg .= "Message:\t$message\n\n";

    $recipient = "myemailaddress@mysite.net";
    $subject = "Web Site Feedback";


    $mailheaders = "From: My Web Site <> \n";
    $mailheaders .= "Reply-To: $sender_email\n\n";

    mail($recipient, $subject, $msg, $mailheaders);

    echo "<html><head><title>Form Sent!</title></head></body>";
    echo "<h1 align=center>Thank You, $sender_name</h1>";
    echo "<p align=center>Your feedback has been sent.</p>";
    echo "</body></html>";

    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    You need to read your form variables ... using $_POST as specified in your <form> ...

    $msg = "Sender Name:\t $_POST['sender_name'] \n";
    $msg .= "Sender E-Mail:\t $_POST['sender_email'] \n";
    $msg .= "Message:\t $_POST['message'] \n\n";


    I won't even go into captcha, validation, or other security issues.
    You're doing just the basic email "as-is".


    .
    Last edited by mlseim; 03-17-2010 at 08:42 PM.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    PHP3 regiser_global reliance. At least this will be gone soon
    There is no such thing as $sender_name, $sender_email, or $message. Extract those out of the $_POST superglobal array: $_POST['sender_name'], $_POST['sender_email'], $_POST['message'].

    Not sure what you're doing with the track_vars there, but best I know that directive hasn't existed since like 4.1. That was used to push information into the _* superglobals from the HTTP_*_VARS, but hasn't been necessary since as of 4.1 the track_vars was enabled by default (and best I know, cannot be disabled). Its been soooooooo long since I've used that though, so I can't be 100% certain but I believe that it was an INI_PER_DIR directive, not an INI_ALL directive. So that wouldn't have even worked at the time embedded in a script :$

    Edit:
    Just checked the API on that one. Track_vars was removed in 4.0.3, and has an unknown PHP_INI_ALL directive. So it would work if properly used at the time embedded directly into a script.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New Coder
    Join Date
    Mar 2010
    Posts
    42
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I know very little about PHP, I got this code of some coding website......didn't know the "php_vars" tag was outdated!
    I tried the code the first poster mentioned (name slips my mind) and it came up with this error message:


    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a3864192/public_html/do_sendform.php3 on line 3

    Like I said, I know very little about PHP, so I don't understand this.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Complexity issue on the use of arrays. A few approaches:
    PHP Code:
    $msg "Sender Name:\t {$_POST['sender_name']} \n";
    $msg .= "Sender E-Mail:\t {$_POST['sender_email']} \n";
    $msg .= "Message:\t {$_POST['message']} \n\n"
    or
    PHP Code:
    $msg "Sender Name:\t " $_POST['sender_name'] . "\n";
    $msg .= "Sender E-Mail:\t " $_POST['sender_email'] . "\n";
    $msg .= "Message:\t " $_POST['message'] . "\n\n"
    or (probably my favorite, I like using format options):
    PHP Code:
    $msg sprintf("Sender Name:\t%s\n"$_POST['sender_name']);
    $msg .= sprintf("Sender E-Mail:\t%s\n"$_POST['sender_email']);
    $msg .= sprintf("Message:\t%s\n\n"$_POST['message']); 
    Next time you search for any scripts in php, I'd recommend searching for "PHP5 scripttype". That should reduce the number of PHP3 popups you get, which is long long outdated (PHP4 is getting very close).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Mar 2010
    Posts
    42
    Thanks
    5
    Thanked 0 Times in 0 Posts
    THANK YOU SO MUCH Fou-lu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It worked!!!

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    oops ... I missed the { } ... I forgot about that.
    Glad that was caught.


  •  

    Posting Permissions

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