This question already has answers here:
How to show or hide a form using php?
(5 answers)
Closed 9 years ago.
I have a contact form that I would like to hide after someone has completed and submitted their information. Below is the code. Ideally, I would like to hide everything between the HTML fieldset tags. I know this can be done with jQuery, but is it possible with PHP?
<form id="contact" method="post" action="index.php">
<fieldset>
<label for="name">Full Name<span class="red"> *</span></label>
<input type="text" name="name" title="Enter your name" required>
<label for="email">E-mail Address<span class="red"> *</span></label>
<input type="email" name="email" placeholder="yourname#domain.com" title="Enter your e-mail address" required>
<label for="phone">Phone Number</label>
<input type="tel" name="phone" title="Enter your phone number" placeholder="ex. (555) 555-5555">
<label for="message">Questions and Comments<span class="red"> *</span></label>
<textarea type="text" name="message" title="Enter your questions or comments" required></textarea>
<label>What is 4+2? (Anti-spam)<span class="red"> *</span></label>
<input type="text" name="human" placeholder="Answer Here" title="Answer Here" required>
<input type="submit" name="submit" class="button" id="submit" value="Send Us A Message" title="Send us a message" />
<p class="red">
* Indicates the field is required.
</p>
</fieldset>
<!-- Contact Form Details -->
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'This message has been sent from your website.';
$to = 'user#domain.com';
$subject = 'From your contact form';
$human = $_POST['human'];
$body = " From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '6') {
if (mail($to, $subject, $body, $from)) {
echo '
<h2>Thank You!</h2>
<span class="message">
Your message has been sent!
</span>';
} else {
echo '
<h2>Oops!</h2>
<span class="message">
Something went wrong, go back and try again!
</span>';
}
} else if ($_POST['submit'] && $human != '6') {
echo '
<h2>Incorrect Answer!</h2>
<span class="message">
The correct answer is 6. Please try again.
</span>';
}
?>
</form>
UPDATE: After trying a few suggestions, I realized that since the page was reloading after the form was submitted, trying to hide the form was pointless. You hit submit, form disappears, page reloads, form is there again. So I surrounded the from in a container and modified the CSS, so the message appears above the form, which is fine. Thank you all for the help though. It's appreciated!
On success, set a variable:
$success = true;
Then surrounding the HTML form:
<?php echo $success ? '<!--' : ''; ?>
// form here...
<?php echo $success ? '-->' : ''; ?>
Try this:
if(!isset($_POST['submit']))
{
<form id="contact" method="post" action="index.php">
<!--Contents in between-->
</form>
}
Also change your html to:
<form id="contact" method="post" action="index.php">
<fieldset>
<label for="name">Full Name<span class="red"> *</span></label>
<input type="text" name="name" title="Enter your name" required>
<label for="email">E-mail Address<span class="red"> *</span></label>
<input type="email" name="email" placeholder="yourname#domain.com" title="Enter your e-mail address" required>
<label for="phone">Phone Number</label>
<input type="tel" name="phone" title="Enter your phone number" placeholder="ex. (555) 555-5555">
<label for="message">Questions and Comments<span class="red"> *</span></label>
<textarea type="text" name="message" title="Enter your questions or comments" required></textarea>
<label>What is 4+2? (Anti-spam)<span class="red"> *</span></label>
<input type="text" name="human" placeholder="Answer Here" title="Answer Here" required>
<input type="submit" name="submit" class="button" id="submit" value="Send Us A Message" title="Send us a message" />
<p class="red">
* Indicates the field is required.
</p>
</fieldset>
</form>
<!-- Contact Form Details -->
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'This message has been sent from your website.';
$to = 'user#domain.com';
$subject = 'From your contact form';
$human = $_POST['human'];
$body = " From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '6') {
if (mail($to, $subject, $body, $from)) {
echo '
<h2>Thank You!</h2>
<span class="message">
Your message has been sent!
</span>';
} else {
echo '
<h2>Oops!</h2>
<span class="message">
Something went wrong, go back and try again!
</span>';
}
} else if ($_POST['submit'] && $human != '6') {
echo '
<h2>Incorrect Answer!</h2>
<span class="message">
The correct answer is 6. Please try again.
</span>';
}
?>
Dont include Contact Form Details inside <form>...</form>
Why not put the php code above the form and add an if condition? If you want to show the form only one time for the whole browser session, you have to use php sessions to store an flag.
<form id="contact" method="post" action="index.php">
<fieldset>
<!-- Contact Form Details -->
<?php
$success = false;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'This message has been sent from your website.';
$to = 'user#domain.com';
$subject = 'From your contact form';
$human = $_POST['human'];
$body = " From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '6') {
if (mail($to, $subject, $body, $from)) {
$success = true;
echo '
<h2>Thank You!</h2>
<span class="message">
Your message has been sent!
</span>';
} else {
echo '
<h2>Oops!</h2>
<span class="message">
Something went wrong, go back and try again!
</span>';
}
} else if ($_POST['submit'] && $human != '6') {
echo '
<h2>Incorrect Answer!</h2>
<span class="message">
The correct answer is 6. Please try again.
</span>';
}
if ($success) {
?>
<label for="name">Full Name<span class="red"> *</span></label>
<input type="text" name="name" title="Enter your name" required>
<label for="email">E-mail Address<span class="red"> *</span></label>
<input type="email" name="email" placeholder="yourname#domain.com" title="Enter your e-mail address" required>
<label for="phone">Phone Number</label>
<input type="tel" name="phone" title="Enter your phone number" placeholder="ex. (555) 555-5555">
<label for="message">Questions and Comments<span class="red"> *</span></label>
<textarea type="text" name="message" title="Enter your questions or comments" required></textarea>
<label>What is 4+2? (Anti-spam)<span class="red"> *</span></label>
<input type="text" name="human" placeholder="Answer Here" title="Answer Here" required>
<input type="submit" name="submit" class="button" id="submit" value="Send Us A Message" title="Send us a message" />
<p class="red">
* Indicates the field is required.
</p>
<?php } ?>
</fieldset>
</form>
Related
I am working on my version 2 of my portfolio site, I had a working mailer I created with a guide about a year ago, transferred it, and can't get my page to display now.
Here is the code I am using:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo <form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>
}
?>
I ran it through a PHP syntax checker and it did not pull anything out, does anyone have any ideas?
For reference: Here is the original code I used on Version 1. I formatted it so it would display the email a little more cleaner, which probably royally screwed it up.
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My Portfolio Website"] ;
$message = $_REQUEST['message'].", Name: ".$name.", ".$phone.", Email: ".$email;
mail("TylerJStelmach#gmail.com", $subject, $message, "From:" . $email);
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo "<form method='post' action='index.php'>
<input type='text' input name='name' id='name' class='contacttext' placeholder=' Your Name' required>
<input type='text' input name='email' id='email' class='contacttext' placeholder=' Your Email Address' required>
<textarea input type='text' name='message' id='message' class='contacttext' placeholder=' Your Message' cols='55' rows='5' required></textarea>
<input type='submit' id='submit' class='submitcontacttext' value='Send Message'>
</form>";
}
?>
There are some syntax errors.
Also, your snipplet does not contain code to send mail.
Corrected code is as following:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo '<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>';
}
?>
as all are saying where is the line to send mail but as i have seen your site there is no sign of any code.
as i am just guessing, even if the if is false, the else should run as it is running in my localhost.
the problem must be something with your sever.
put a error_reporting(E_ALL); on top it will show errors if it there.
else try writing in a new file.
<?php
error_reporting(E_ALL);
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
?>
<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>
<?php
}
?>
I was able to figure this out by re-writing the original code I had based on the guide I used about a year ago, I came up with this for the answer which indeed works.
For all of the handling of where the information goes and how it was formated I included this chunk of php before I declared the doctype.
<?php
if($_POST["submit"]) {
$recipient="myemail#email.com";
$subject="Client Mail";
$name=$_POST["name"];
$email=$_POST["email"];
$email_from = $_POST['email'];
$message=$_POST["message"];
$mailBody="Name: $name\nEmail: $email\n\nMessage: $message";
mail($recipient, $subject, $mailBody, "From: $sender <$email>");
$thankYou="<p class='thank-you'>Thank you! Your message has been sent.</p>";
}
?>
From here, I figured out that the reason it wasn't submitting to it's own page was because my submit button was neither a button or input. I had it set as a div so with some tweaks here and there I rewrote the lower half to include an input as the submit. Which left me with this:
<?=$thankYou ?>
I included a small amount of text to display ( the $thankYou ) when you submit to the page and it reloads.
<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<input type="submit" name="submit" class="metro-button submit-me">
</div>
</form>
So now when submitted, the email comes in with:
The 'from' being set by $email
The 'subject' being set by $subject
and the message ($message) being formatted in this manner:
Name: John Doe
Email: JDoe#fake.com
Message: This is John Doe's message.
My apologies for the terrible question phrasing before hand, it was late at night and I was getting frustrated and losing my place, got a good nights rest and was able to solve it.
Here is the live version, I encourage you to test it, it works for me perfectly, hopefully this snippet can help someone else in the future!
I've been looking around everywhere and cannot seem to find how to make this work - it is simply not sending an email to my address. Here is my HTML form:
<form id="contactMe" name="contact" method="post" novalidate="novalidate">
<fieldset>
<label for="name" id="name">Name<span class="required">*</span></label>
<input type="text" name="name" id="name" size="30" value="" required="">
<label for="email" id="email">Email<span class="required">*</span></label>
<input type="text" name="email" id="email" size="30" value="" required="">
<label for="phone" id="phone">Phone</label>
<input type="text" name="phone" id="phone" size="30" value="">
<label for="Message" id="message">Message<span class="required">*</span></label>
<textarea name="message" id="message" required=""></textarea>
<label for="Answer" id="answer">Name the house pet that says “<i>woof</i>“<span class="required">*</span></label>
<input type="text" name="answer" value="" required=""></br>
<input id="submit" type="submit" name="submit" value="Send">
</fieldset>
<div id="success">
<span class="green textcenter">
<p>Your message was sent successfully! I will be in touch as soon as I can.</p>
</span>
</div> <!-- closes success div -->
<div id="error">
<span><p>Something went wrong, try refreshing and submitting the form again.</p></span>
</div> <!--close error div-->
</form>
and here is my PHP saved as mailer.php:
<?php
$to = "someone#gmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "You have a message from your.";
$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
mail("maytee.kneitz#gmail.com",$subject,$message,"From: $from\n");
echo 'Mail sent';
?>
This is my first shot at working on a mailer / contact form, so sorry if it's a blatant problem. I just can't seem to find it. Any guidance would be appreciated.
I do have validation in my scripts (not posted here).
You don't have a form action defined. Try this:
<form id="contactMe" name="contact" method="post" action="mailer.php" novalidate="novalidate">
By default, the form will be submitted to its current location unless otherwise specified. In your case, point it to wherever your mail script is located
I have written some PHP code for a contact form for my one page portfolio, when it is submitted it just opens up a blank page and also the e-mail isnt sent and the text is not echo'd out. I am not very confident with PHP as it is fairly new to me. if anyone could help that would be great?
html -
<form id="cont-form" method="post" action="mail.php">
<fieldset>
<legend>Send me a message</legend>
<ol>
<li>
<label for="name">Name</label>
<input id="name" name="name" type="text" placeholder="First and last name" required autofocus>
</li>
<li>
<label for="email">Email</label>
<input id="email" name="email" type="email" placeholder="example#domain.com" required>
</li>
<li>
<label for="phone">Phone</label>
<input id="phone" name="phone" type="tel" placeholder="Eg. 07500000000" required>
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" type="text" placeholder="What the message is about" required>
</li>
<li>
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Insert your message or question here" rows="10" cols="50">
</textarea>
</li>
<li>
<label for="human">What is 2 + 2 ?</label>
<input id="human" name="human" type="number" placeholder="Please insert answer" required>
</li>
</ol>
</fieldset>
<fieldset>
<input class="button" id="submit" type="submit" value="Send it!">
</fieldset>
</form>
php -
<?php
$name = $_POST['name']; //'name' has to be the same as the name value on the form input element
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: $email';
$to = 'ben_humphries#hotmail.co.uk'; //set to the default email address
$subject = $_POST['subject'];
$human = $POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '4') {
if (mail ($to, $subject, $body, $from)) { //mail sends it to the SMTP server side which sends the email
echo "<p>Your message has been sent!</p>";
} else {
echo "<p>Something went wrong, go back and try again!</p>";
}
} else if ($_POST['submit'] && $human != '4') {
echo "<p>You answered the anti-spam question incorrectly!</p>";
}
?>
There were a few things wrong with your form and handler.
In your HTML form, you did not have an input for human so I added that, plus your submit button was not named, so that alone would not have worked.
<input class="button" id="submit" name="submit" type="submit" value="Send it!">
And in your PHP handler, your (mail headers) were improperly formatted, so that ended up in my SPAM box so I added that as well.
$from = $_POST['email'];
as well as headers plus I fixed your last condition to:
if (!isset($_POST['submit']) && ($_POST['human']) != '4')
HTML form
<form id="cont-form" method="post" action="mail.php">
<fieldset>
<legend>Send me a message</legend>
<ol>
<li>
<label for="name">Name</label>
<input id="name" name="name" type="text" placeholder="First and last name" required autofocus>
</li>
<li>
<label for="email">Email</label>
<input id="email" name="email" type="email" placeholder="example#domain.com" required>
</li>
<li>
<label for="phone">Phone</label>
<input id="phone" name="phone" type="tel" placeholder="Eg. 07500000000" required>
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" type="text" placeholder="What the message is about" required>
</li>
<li>
<label for="human">What is 2 + 2 ?</label>
<input id="human" name="human" type="number" placeholder="Please insert answer" required>
</li>
<li>
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Insert your message or question here" rows="10" cols="50">
</textarea>
</li>
</ol>
</fieldset>
<fieldset>
<input class="button" id="submit" name="submit" type="submit" value="Send it!">
</fieldset>
</form>
PHP handler, tested and working for you.
<?php
$name = $_POST['name']; //'name' has to be the same as the name value on the form input element
$email = $_POST['email'];
$message = $_POST['message'];
$human = $_POST['human'];
$from = $_POST['email'];
$to = 'ben_humphries#hotmail.co.uk'; //set to the default email address
$subject = $_POST['subject'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if(isset($_POST['submit']) && ($_POST['human']) == '4') {
mail ($to, $subject, $body, $headers); //mail sends it to the SMTP server side which sends the email
echo "<p>Your message has been sent!</p>";
}
else {
echo "<p>Something went wrong, go back and try again!</p>";
}
if (!isset($_POST['submit']) && ($_POST['human']) != '4') {
echo "<p>You answered the anti-spam question incorrectly!</p>";
}
?>
i'm getting blank field returns in my inbox on only a portion on my form fields
like so:
From: whatevername
Email: fgsdfg#fakeysite.com
Message:
phone:
here is my code its probably something really dumb but its bugging me, so here we go.
HTML
<div class="row-item col-1_4">
<h3>Contact Form</h3>
<h4>Please fill out the form to get your free CD Replacement Kit</h4>
<!-- Success Message -->
<div class="form-message"></div>
<!-- Form -->
<form class="b-form b-contact-form" action="blast.php">
<div class="input-wrap m-full-width">
<i class="icon-user"></i>
Name
<input class="field-name" type="text" placeholder="Name (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-phone"></i>
Phone
<input class="field-phone" type="text" placeholder="Phone">
</div>
<div class="input-wrap m-full-width">
<i class="icon-envelope"></i>
Email
<input class="field-email" type="text" placeholder="E-mail (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-pencil"></i>
Message
<input class="field-comments" type="text" placeholder="Message">
</div>
<input class="btn-submit btn colored" type="submit" value="Send">
</form>
PHP
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient = "csmith#legacybrokerage.com";
$subject = "UNLIMITED ANNUITY LEADS CD BLAST";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
try this, define name= 'something' to the input field
<input class="field-name" type="text" placeholder="Name (required)" name="name">
<input class="field-phone" type="text" placeholder="Phone" name="phone">
<input class="field-email" type="text" placeholder="E-mail (required)" name="email">
your input's dose not name attribute!
<input class="field-name" type="text" placeholder="Name (required)">
correct :
<input name="from" class="field-name" type="text" placeholder="Name (required)">
I'm a total novice so please bear with me :)…I've managed to create a form and used PHP to send the data to an email address. However, once I click submit; the screen goes blank instead of staying on the current page and displaying a message. I'm guessing i'm missing some sort of PHP code?
Also, i'd like to use the JQuery validator plugin on my form, how can I add it without basically screwing up the form?
MY HTML:
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
MY PHP:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
PHP script that you create will return an empty page, because that script just to send email. I think you need to combine PHP script and HTML script together with PHP script in top of script to get that you want and edit form action to empty like this sample:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
<div>
<form id="form_id" name="form_name" action="" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
Your form will take the user to scripts/index.php. You are echoing the '$feedback' var on the page with the HTML form. Redirect from scripts/index.php using
header("location: filelocation");
exit();
You can achieve this in two ways :
1. Have php and html code in one page.
2. Use ajax to submit your form.
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
</div>
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
echo '<p id="feedback">'.$feedback.'</p>'; <-- Notice this..
}
?>
You can also use ajax in jquery ($.ajax) or javascript.