tekgrl
asked on
PHP form -- thank you message display on same page
Hi all, I need a very simple PHP contact form (email address only) that displays the thank you message (or form failed) on the same page as the form. In other words, no redirect page.
Extra points if the form validates.
Thank you!!
Extra points if the form validates.
Thank you!!
Please refer attached code...make changes as you needed
<?
// file: index.php
if($_POST['submit']){
if($_POST['email'] != ""){
echo $_POST['email'];
echo "Thank you for contacting us";
}else{
echo "Error no email entered";
}
}else{ ?>
<html>
<head><title></title></head>
<body>
<form action="index.php" method="post">
<input type="text" name="email" value=""/>
</form>
</body>
</html>
<?}?>
Never rely on JavaScript to do form validation. JavaScript can be bypassed completely, so dangerous (code injection) data can be submitted to your server.
ASKER
Neither of these worked. Nothing showed up on the first example and no input button for the second one...
While I have no issues using Javascript, here is one without, much like kalmax's version. But allows the form to display if no email address was submitted.
<?php
if($_POST['email'] != ""){
echo $_POST['email'];
echo " Thank you for your email";
}else{
if($_POST['submitted'] !=""){
echo "Error no email entered";
}
echo "<html><head></head><body>";
echo "<form action=form_page.php method=post>";
echo "Email Address:<input type=text name=email />";
echo "<input type=hidden value=submitted name=submitted>";
echo "<input type=submit value=Submit>";
echo "</form></body>";
}
?>
ASKER
Hey Daniel, maybe I'm missing something. The form action is "form_page.php". Where is that page? I'm hoping it sends an email notification to someone.
Name that code as a page called form_page.php
So that it submits to itself. You can call it whatever you want. just be sure to fix the action to whatever you named it.
So that it submits to itself. You can call it whatever you want. just be sure to fix the action to whatever you named it.
ASKER
I see. Yes, that works, but I need the form to send an email to me notifying me that someone has submitted their email via the form. How do I do that?
Short of writing this entire thing for you,
You could add this to the code, i think you can figure that out, its pretty self explanatory.
You could add this to the code, i think you can figure that out, its pretty self explanatory.
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
ASKER
I would love for you to write the entire thing for me! Alas...
Here is what I came up with. Not getting the email alert though.
Here is what I came up with. Not getting the email alert though.
<?php
// Contact subject
$subject = 'Somebody signed up';
// Details
$message= $_POST['email'];
// Mail of sender
$mail_from= $_POST['email'];
// From
$header="from: me@me.com";
// Enter your email address
$to ='me@me.com';
$send_contact=mail($to,$subject,$message,$header);
if($_POST['email'] != ""){
echo "Thank you for your email";
}else{
if($_POST['submitted'] !=""){
echo "Error no email entered";
}
echo "<html><head></head><body>";
echo "<form action=footer2.php method=post>";
echo "Email Address:<input type=text name=email />";
echo "<input type=hidden value=submitted name=submitted>";
echo "<input type=submit value=Submit>";
echo "</form></body>";
}
?>
your not doing the sendmail in the thank you area.
put it after line 15
I am not sure what your doing with the $mail_from or $send_contact either
use the codefor the send mail i posted
put it after line 15
I am not sure what your doing with the $mail_from or $send_contact either
use the codefor the send mail i posted
ASKER
Here's what I have... Still no email notification.
Also, I don't understand how I'm going to get the submitted email address with this code.
Also, I don't understand how I'm going to get the submitted email address with this code.
<?php
if($_POST['email'] != ""){
echo $_POST['email'];
echo " Thank you for your email";
}else{
if($_POST['submitted'] !=""){
echo "Error no email entered";
}
echo "<html><head></head><body>";
echo "<form action=footer2.php method=post>";
echo "Email Address:<input type=text name=email />";
echo "<input type=hidden value=submitted name=submitted>";
echo "<input type=submit value=Submit>";
echo "</form></body>";
}
$to = 'me@me.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
your not going to, you have to CALL the email portion after the email is captures in the return $_POST in line 2
move the code for the email after line 2.....
move the code for the email after line 2.....
ASKER
How do I call the email portion?
as I said, MOVE THE CODE FOR THE EMAIL TO LINE 3
thats it....
I would also suggest a PHP manual to get some basics of PHP
thats it....
I would also suggest a PHP manual to get some basics of PHP
ASKER
Okay...I'm really confused. I've attached what I have. It's not working. You could put us both out of our misery and just post a little code. I have better things to do today, and I'm sure you do too.
<?php
if($_POST['email'] != ""){
$to = 'me@me.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo $_POST['email'];
echo " Thank you for your email";
}else{
if($_POST['submitted'] !=""){
echo "Error no email entered";
}
echo "<html><head></head><body>";
echo "<form action=footer2.php method=post>";
echo "Email Address:<input type=text name=email />";
echo "<input type=hidden value=submitted name=submitted>";
echo "<input type=submit value=Submit>";
echo "</form></body>";
}
?>
. I copied your code and used it. Worked like a champ
You DID change the FROM, REPLY TO and TO addresses right? (line 3,6,7)
Are you getting the THANK YOU FOR YOUR EMAIL when you submit?
You need to be more specific about whats NOT working
You DID change the FROM, REPLY TO and TO addresses right? (line 3,6,7)
Are you getting the THANK YOU FOR YOUR EMAIL when you submit?
You need to be more specific about whats NOT working
ASKER
That is right. I am NOT getting the email. Yes, I changed those addresses to my own.
Are you getting the THANK YOU FOR YOUR EMAIL?
If not then it sounds like your not submitted to the page correctly. there isnt much more I can you, the code is right on, ive tested it just as you posted with expection of my email addresses and it works correctly.
If not then it sounds like your not submitted to the page correctly. there isnt much more I can you, the code is right on, ive tested it just as you posted with expection of my email addresses and it works correctly.
ASKER
Hmmmm. Well I guess that's it for us then. Can somebody else try it and see if it works for them too?
again i ask, are you getting the THANK YOU FOR YOUR EMAIL text when you submit the email address?
You have to help yourself some by answering questions
You have to help yourself some by answering questions
ASKER
Yes, I get that message.
ok so the codes working, your mail part is not
if the code is exactly as you posted above with expection of YOUR email accounts in place instead of the me@me.com then its working.
make a simple PHP page with this in it nothing else
This will just test the phpmail. be sure to replace the your@email.com with your email address
make the page, load the page and see if you get email
if the code is exactly as you posted above with expection of YOUR email accounts in place instead of the me@me.com then its working.
make a simple PHP page with this in it nothing else
This will just test the phpmail. be sure to replace the your@email.com with your email address
make the page, load the page and see if you get email
<?
$mail_sent = @mail('your@email.com', 'My Subject', 'test body message');
echo $mail_sent;
?>
ASKER
I didn't get the email. What does that mean?
what did the echo display?
ASKER
1
1 means the email sent, it responded as TRUE which means it sent successfully.
ASKER
Okay, I guess this is my problem, not yours. Checked all my spam filter... no email. Will you please do me a favor and check my attached file once more?
footer5.php
footer5.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can add the code for that in get_response.php file. Here is the code:
Source: contact form in php
if(!$result = $conn->query($sql)){
die('There was an error running the query [' . $conn->error . ']');
}
else
{
echo "Thank you! We will contact you soon";
}
}
else
{
echo "Please fill Name and Email";
}
?>
Source: contact form in php
Should get the point tho.
Open in new window