PDA

View Full Version : Echo Function in a PHP Mail Form



mourningwear
January 5th, 2007, 08:51 PM
Hi, I'm trying to learn what all the variables in PHP mean, and how they make a website function. I read the PHP Mail form turtorial on the site, and integrated it into my site, and that part is working great (receiving form submissions, etc).
The only problem I'm having is in what happens once you click submit.
Currently, once you click submit it takes you from the page to the text that is in the echo function (i.e. "Thanks for submitting your information")
I really would like to know how I can manipulate the PHP form so that when someone clicks submit, it still sends the information, but stays on the same page.
Any ideas?
Thanks!!!

Here is the what the code looks like, btw:


<?php
if(isset($_POST['submit'])) {

$to = "emailaddress@gmail.com";
$subject = "Subject";
$name_field = $_POST['name'];
$email_field = $_POST['email'];

foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}

$body = "From: $name_field\n E-Mail: $email_field\n";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {
echo "try again!";
}
?>

nobody
January 5th, 2007, 10:00 PM
You need to set your form action to the same page that you're on. Then you'll put that code at the top inside the body tags of your php file, though it may already by structured like that, I don't know. You can take out the echo if you want and just have it display the form again, or you can echo nothing. If you can show the whole file and maybe explain a bit better what you're trying to do I'd be happy to help further.

mourningwear
January 6th, 2007, 12:02 AM
I definitely appreciate you pointing me in the right direction!
Most importantly, I got it working using your advice.
I've only been using PHP for a couple of weeks, but I'm really excited to be figuring it out.
Thanks again!