Hi I need help with a contact php form. I am creating a html5 website and I can
ID: 3692229 • Letter: H
Question
Hi I need help with a contact php form. I am creating a html5 website and I can not figure out what I am doing wrong. When you click submit on the contact form it brings up my php page. I would like it to say on the contact page (where the contact form is) Thank you for sending your message. Instead it takes me to my php page. Also i can not get the php to direct to my email. what I mean by this; is when the user fills out the contact form and clicks send i should recieve an email to my email address with the contact form information the user just filled out. Below is my css my html5 and my php. Thanks in advance
CSS
body {
background: #FFFFFF;
font: 1em/1.5em Verdona, Geneva, Sans-serif;
color: #79CDCD;
margin: 0;
width: 100%;
height: auto;
}
header {
width: 100%;
height: auto;
background: #D3D3D3;
}
h1, h2 {
text-align: center;
padding-left: 0%;
padding-top:0%;
color: #79CDCD;
font-size: 320%;
font-weight:bold;
}
.textchange{
color:#79CDCD;
font:Verdona, Geneva, Sans-serif;
font-weight:bold;
text-align:center;
}
.container1{
vertical-align:middle;
padding-top: 3.5%;
}
.container2 {
max-width:400px;
width:100%;
margin:0 auto;
position:relative;
}
h3 {
text-align: left;
padding-left: 1%;
color: #79CDCD;
}
p{
color: #000000;
text-align: left;
}
img {
text-align: center;
height: 100%;
width: auto;
}
.clearbox {
clear: both;
}
.social {float: right;
}
.social ul {
margin-top: 10px;
}
.social li {
display: inline;
}
.logo{
width: 220%;
padding-top: 20%;
}
.banner{
width: 220%;
padding: 5%;
}
.nav1{
padding-top: 8%
}
a {
color: #c52d2f;
text-decoration: none;
text-shadow : 0px;
font-style: Bold;
}
.navbar-brand {
float: left;
font-size: 29px;
height: 50px;
line-height: 20px;
padding: 0px;
}
.navbar-brand, .navbar-nav > li > a {
color : #000000;
padding-bottom: 7px;
padding-top: 7px;
}
.nav > li > a:focus, .nav > li > a:hover {
background-color : #79CDCD;
font-style: Bold;
color: #79cdcd;
border-radius: 10px;
}
.container1 {
width: 90%;
float: left;
margin: 2% 5%;
padding-left: 8%;
text-align: left;
}
.margin{
margin:5%;
}
.margin1{
padding:4%;
}
footer {
background: #D3D3D3;
width: 100%;
overflow: hidden;
padding-top:2%;
}
footer p, footer h4{
color: #000000;
font-weight: bold;
text-align: center;
}
#contact input[type="text"], #contact input[type="email"], #contact input[type="tel"], #contact textarea, #contact button[type="submit"] { font:400 12px/16px "Open Sans", Helvetica, Arial, sans-serif; }
#contact {
background:#000000;
padding:10px;
margin:10px 0;
}
#contact h3 {
color: #79cdcd;
display: block;
font-size: 16px;
}
#contact h4 {
display:block;
font-size:15px;
text-align:center;
}
fieldset {
border: medium none !important;
margin: 0 0 10px;
min-width: 100%;
padding: 0;
width: 100%;
}
#contact input[type="text"], #contact input[type="email"], #contact input[type="tel"], #contact input[type="url"], #contact textarea {
width:100%;
border:1px solid #CCC;
background:#FFF;
margin:0 0 5px;
padding:10px;
}
#contact input[type="text"]:hover, #contact input[type="email"]:hover, #contact input[type="tel"]:hover, #contact input[type="url"]:hover, #contact textarea:hover {
-webkit-transition:border-color 0.3s ease-in-out;
-moz-transition:border-color 0.3s ease-in-out;
transition:border-color 0.3s ease-in-out;
border:1px solid #AAA;
}
#contact textarea {
height:100px;
max-width:100%;
resize:none;
}
#contact button[type="submit"] {
cursor:pointer;
width:100%;
border:none;
background:#79cdcd;
color:#000000;
margin:0 0 5px;
padding:10px;
font-size:15px;
font-weight:bold;
}
#contact button[type="submit"]:hover {
background:#09C;
-webkit-transition:background 0.3s ease-in-out;
-moz-transition:background 0.3s ease-in-out;
transition:background-color 0.3s ease-in-out;
}
#contact button[type="submit"]:active { box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.5); }
#contact input:focus, #contact textarea:focus {
outline:0;
border:1px solid #999;
}
::-webkit-input-placeholder {
color:#888;
}
:-moz-placeholder {
color:#888;
}
::-moz-placeholder {
color:#888;
}
:-ms-input-placeholder {
color:#888;
}
.ContactText{
font-family:"Open Sans", Helvetica, Arial, sans-serif;
font-weight:300;
font-size: 12px;
line-height:30px;
color:#777;
background:#0CF;
}
@media only screen and (max-width: 768px) {
.social {
margin: 0 auto;
}
.social ul {
margin: 0 auto;
}
.social li{
display:inline
}
.nav1{
padding-top: 0%;
margin: 0 auto;
text-align:center;
}
.container1{
width: 100%;
margin: 0% 0%;
padding-left: 0%;
text-align: center;
}
.container4 {
width: 90%;
float: left;
margin: 2% 5%;
text-align: center;
}
h3{
text-align:center;
}
.logo{
width: 100%;
padding-left: 10%;
}
}
html5
KE Designs Contact Page
Toggle navigation
Home
About
Contact
Shop
Rings
Bracelets
Necklaces
Contact Us
Via Phone
Via Email
Fill out the form below and click send.
Name:
Email Address:
Message:
Send
KEdesigns@aol.com
©Copyright - Anarchy by Gina Eberhardt, 2016.
1-866-123-4567
PHP
$name = $_POST['name'];
$name = $_POST['lname'];
$email = $_POST['email'];
$from = 'From: KE Designs.com'
$to = "myEmail@gmail.com"
$subject = 'Email Inquiry';
$body = "From: $name E-mail: $email Message: $message";
?>
If ($_POST['submit']) {
If (mail ($to, $subject, $body, $from)) {
echo '
Thank you for your email!
;
}else{
echo '
Oops! An error occured. Try sending your message again.
}
}
?>
Explanation / Answer
Try the below suggessions.I think these may be helpful.......
POINT 1.
=========
TWO METHODS ARE PRESENT WHERE A PAGE AFTER FORM SUBMISSON IS STAYED ON THE SAME PAGE....
METHOD A.Use the below statement
------------------
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
OR
METHOD B.Use the below set of example code--- IT SURELY MAKES PAGE TO STAY AFTER FORM SUBMIT
-----------------
if(isset($_POST['SubmitButton'])) //check if form was submitted
{
// Enter the Code you want to execute after the form has been submitted
// Dispaly Success or failure Message if any
$input = $_POST['inputText']; //get input text
$message = "Success! You entered: ".$input;
}
?>
POINT 2.
==========
REGARDING EMAILS....
Use double quotes instead of single quotes.Also first check whether mail is sending or not and then keep the mail() in IF condition.
Also keep some hard coded text message as below example in the email body part,if email is successfully sent then later replace hard coded message in email body with your required code.
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . " " .
"CC: somebodyelse@example.com";
mail($to,$subject,$txt,$headers);
?>
<html>
<body>
<form action="" method="post">
<?php echo $message; ?>
<input type="text" name="inputText"/>
<input type="submit" name="SubmitButton"/>
</form>
</body>
</html>
POINT 3.
=========
Also instead of the below statement in email section of your code....
$body = "From: $name E-mail: $email Message: $message";
Use the below statement for getting the input variable values....
$body = "From: ".$name." E-mail: ".$email." Message: ".$message";