contact form submit not responding - php

I am having a problem with the contact form and when I am trying to submit the form, it's not responding and please help me to solve this issue.below is the code
HTML:
<form action="contact-form-handler.php" method="post"
class="contactForm">
<div class="row">
<div class="span4 form-group field">
<input type="text" name="name" placeholder="Your Name" data-
rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="span4 form-group">
<input type="email" name="email" placeholder="Your Email"
data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="span8 form-group">
<textarea name="message" rows="5" data-rule="required" data-
msg="Please write something for us" placeholder="Message">
</textarea>
<div class="validation"></div>
<div class="text-center">
<button class="btn btn-success" type="submit"
value="sendmessage">Send message</button>
Please find the below php code for the submit form and please give me the solution on how i can solve this issue. Thanks in advance.
if (isset($_POST['submit'])) {
$name=$_POST['name'];
$email=$_POST['email'];
// $subject=$_POST['subject'];
$msg=$_POST['msg'];
}
$to='contact#****.my';
$subject='Contact Form';
$message="Name: " .$name."\n"."email: " .$email."\n"."Subject: "
.$subject."\n". "Wrote the following: "."\n\n".$msg;
$headers="From:".$email;
if (mail($to, $subject, $message, $headers)) {
echo "<h1>Your message has been sent. Thank you!"."".$name.", We Will
Contact you shortly</h1>";
}
else {
echo "Something went wrong!";
}

You forgot to close your form and didn't gave your submit button a name so your php can't work
<form action="contact-form-handler.php" method="post"
class="contactForm">
<div class="row">
<div class="span4 form-group field">
<input type="text" name="name" placeholder="Your Name" data-
rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="span4 form-group">
<input type="email" name="email" placeholder="Your Email"
data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="span8 form-group">
<textarea name="message" rows="5" data-rule="required" data-
msg="Please write something for us" placeholder="Message">
</textarea>
<div class="validation"></div>
<div class="text-center">
<button class="btn btn-success" type="submit" name="submit"
value="sendmessage">Send message</button>
</form>
and you forgot to close this sentece change it from
$message="Name: " .$name."\n"."email: " .$email."\n"."Subject: "
to
$message="Name: " .$name."\n"."email: " .$email."\n"."Subject: " ;

$msg=$_POST['msg'];
must be
$msg=$_POST['message'];
and
.$subject."\n". "Wrote the following: "."\n\n".$msg;
must be
$subject."\n". "Wrote the following: "."\n\n".$msg;

Related

Send Email submission from Multistep Form

I'm trying to create a multistep form that sends an email to me every time the form has been submitted. The form fully works except it won't send me the email. The code I used does work though for another test I did where the form is not a multistep form.
Here's the code I use:
<form <?php
error_reporting(E_ALL);
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$to='email#email.com'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Email :".$email."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$message;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly!</h1>";
}
else{
echo "Something went wrong!";
}
}
?> method="post" name="form" class="form-box">
<div class="step step-1 active">
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div><br>
<button type="button" class="next-btn">Next</button>
</div>
<div class="step step-2">
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email">
</div><br>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="number" id="phone" name="phone">
</div>
<button type="button" class="prev-btn">Previous</button>
<button type="button" class="next-btn">Next</button>
</div>
<div class="step step-3">
<div class="form-group">
<label for="message">Message</label>
<textarea name="message" class="message-box" placeholder="Enter Your Message Here..."></textarea>
<!-- <input type="text" id="message" name="message">-->
</div>
<button type="button" class="prev-btn">Previous</button>
<button type="submit" name="submit" value="Send" class="submit-btn">Submit</button>
</div>
</form>
Thanks in advance and I hope someone can help me figure it out.

Alert message on sending email not showing up

On sending the email by clicking the send message button an alert box should show up, but it is not coming up neither it is showing inquiry sent successfully nor it is showing email not sent I don't know where I'm going wrong. Please help me resolve this issue.
Any help will be highly appreciable. I'm attaching herewith a part of my contact.php code and my mail.php code.
Thank You
contact.php
<form id="contact-form" method="POST" action="mail.php">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Name</label>
<input class="form-control" name="name" id="name" placeholder="" type="text" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Email</label>
<input class="form-control" name="email" id="email" placeholder="" type="email" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Subject</label>
<input class="form-control" name="subject" id="subject" placeholder="" required>
</div>
</div>
</div>
<div class="form-group">
<label>Message</label>
<textarea class="form-control" name="message" id="message" placeholder="" rows="10" required></textarea>
</div>
<div class="text-right"><br>
<button class="btn btn-primary solid blank button" id="btn" type="submit" value="submit" name="submit">Send Message</button>
</div>
</form>
mail.php
<?php
if (isset($_POST['submit'])){
$to = "contact#imatrixautomation.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$message .="\r\n from: $email";
if(mail ($to, $subject, $name, $message)){
echo "<script>alert('Enquiry sent successfully!');</script>";
}
else
{
echo "<script>alert('Mail was not sent. Please try again later');</script>";
}
}
header('Location: https://imatrixautomation.com/contact.php');
exit;
?>
Replace
<button class="btn btn-primary solid blank button" id="btn" type="submit" value="submit" name="submit">Send Message</button>
To
<input class="btn btn-primary solid blank button" id="btn" type="submit" value="submit" name="submit">
you should add name to your button
<button class="btn btn-primary solid blank button" id="btn" name="submit" type="submit" value="submit">Send Message</button>
also as you're redirecting by changing header it won't show you the alert as alert was on different page.
try this code
<form id="contact-form" method="POST" action="">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Name</label>
<input class="form-control" name="name" id="name" placeholder="" type="text" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Email</label>
<input class="form-control" name="email" id="email" placeholder="" type="email" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Subject</label>
<input class="form-control" name="subject" id="subject" placeholder="" required>
</div>
</div>
</div>
<div class="form-group">
<label>Message</label>
<textarea class="form-control" name="message" id="message" placeholder="" rows="10" required></textarea>
</div>
<div class="text-right"><br>
<button class="btn btn-primary solid blank button" id="btn" name="submit" type="submit" value="submit">Send Message</button>
</div>
</form>
and below this write your php code in same file
<?php
if(isset($_POST['submit'])) {
$to = "contact#imatrixautomation.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$message .= "\r\n from: $email";
if(mail($to, $subject, $name, $message)) {
echo "<script>alert('Enquiry sent successfully!');</script>";
}
else {
echo "<script>alert('Mail was not sent. Please try again later');
</script>";
}
}
?>
In the contact.php file
name="submit" is missing for the submit button.
This line should be:
<button class="btn btn-primary solid blank button" id="btn" type="submit" name="submit" value="submit">Send Message</button>
Explanation:
Currently the
if (isset($_POST['submit'])){
always evaluates to FALSE as POST['submit'] is empty so it continues at the header()...
################
try this code as mail.php and tell us what happens ;-)
<?php
if (isset($_POST['submit'])){
echo "submit is set to {$_POST['submit']} and now we send the email<br>";
$to = "contact#imatrixautomation.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$message .="\r\n from: $email";
if(mail ($to, $subject, $name, $message)){
echo "Enquiry sent successfully!<br>";
}
else
{
echo "Mail was not sent. Please try again later<br>";
}
} else{
echo"submit is not set<br>";
}
echo "after the if condition";
exit;
?>
Here i have the new contact.php file - just copy paste this
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Unbenanntes Dokument</title>
</head>
<body>
<form id="contact-form" method="POST" action="mail.php">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Name</label>
<input class="form-control" name="name" id="name" placeholder="" type="text" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Email</label>
<input class="form-control" name="email" id="email" placeholder="" type="email" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Subject</label>
<input class="form-control" name="subject" id="subject" placeholder="" required>
</div>
</div>
</div>
<div class="form-group">
<label>Message</label>
<textarea class="form-control" name="message" id="message" placeholder="" rows="10" required></textarea>
</div>
<div class="text-right"><br>
<button class="btn btn-primary solid blank button" id="btn" type="submit" name ="submit" value="submit">Send Message</button>
</div>
</form>
</body>
</html>

Send contact form data to email

My goal is to make a contact form, where the user would type their name, email and message. The moment they press "Send", me, as the admin, would receive an email with all the information that was typed in before. Right now the email is sent but its empty, for example:
Reply to:
User name:
User email
User message
Also, when I click on "Send message" it gives me the same form but without CSS, there must be a code mistake which I don't know what it is.
// Form contactos.php
<div class="col-md-7 mb-5 site-animate">
<form action="index.php?cmd=contform" method="post">
<div class="form-group">
<label for="name" class="sr-only">Name</label>
<input type="text" class="form-control" id="NomeM" placeholder="Nome">
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="text" class="form-control" id="EmailMen" placeholder="Email">
</div>
<div class="form-group">
<label for="message" class="sr-only">Messagem</label>
<textarea name="message" id="Mensagem" cols="30" rows="10" class="form-control" placeholder="Escreva a sua mensagem"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Enviar Mensagem">
</div>
</form>
</div>
//File contform.php
<?php
$sql="select * from Mensagem ";
$res=$lig->query($sql);
$lin = $res->fetch_array();
$NomeM = $_POST['NomeM'];
$Email = $_POST['EmailMen'];
$Mensagem = $_POST['Mensagem'];
$email_from = 'admin03#happygreen.pt';
$email_subject = "New Form Submission";
$email_body = "User Name:" .$lin['NomeM']."\n".
"User Email:".$lin['EmailMen']."\n".
"User Message:".$lin['Mensagem']."\n";
$to = "filipajoao1933#gmail.com";
$headers = "De: $email_from \r\n";
$headers .= "Responda a: ".$lin['EmailMen']."\r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: Contactos/contactos.php");
?>
Form fields (input, select, textarea) need a name attribute you can reference in PHP, yours only have ids. Also, the for attribute in labels reference the id of a form field:
// Form contactos.php
<div class="col-md-7 mb-5 site-animate">
<form action="index.php?cmd=contform" method="post">
<div class="form-group">
<label for="NomeM" class="sr-only">Name</label>
<input type="text" class="form-control" name="NomeM" id="NomeM" placeholder="Nome">
</div>
<div class="form-group">
<label for="EmailMen" class="sr-only">Email</label>
<input type="text" class="form-control" id="EmailMen" name="EmailMen" placeholder="Email">
</div>
<div class="form-group">
<label for="Mensagem" class="sr-only">Messagem</label>
<textarea name="Mensagem" id="Mensagem" cols="30" rows="10" class="form-control" placeholder="Escreva a sua mensagem"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Enviar Mensagem">
</div>
</form>
</div>
And your $email_body should be:
$email_body = "User Name:" .$NomeM."\n".
"User Email:".$EmailMen."\n".
"User Message:".$Mensagem."\n";

HTML for is not being submitted after clicking on the submit button

I have the following form:
<form method="post">
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Full Name:</label>
<input type="text" class="form-control" name="name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Email Address:</label>
<input type="email" class="form-control" name="email" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Description</label>
<textarea placeholder="Your text here.." name="description" class="form-control" rows="8" required></textarea>
<p class="help-block"></p>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
<input type="submit" value="Send" name="submit" class="btn btn-success btn-block btn-lg">
</form>
And in the same file below the form, I have the following php form statement where I check if the form is submitted or not:
if (isset($_POST['submit'])) {
echo "<h1>" . "Form is submitted" . "</h1>";
} else {
echo "<h1>" . "Form is not submitted" . "</h1>";
}
After clicking the "Send" button I cannot enter the "Form is submitted" if. I'm not sure why?
This should work, the naming of the submit button wasn't working.
<?php
if (isset($_POST['SubmitForm'])) {
echo "<h1>" . "Form is submitted" . "</h1>";
} else {
echo "<h1>" . "Form is not submitted" . "</h1>";
}
?>
<form method="post">
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Full Name:</label>
<input type="text" class="form-control" name="name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Email Address:</label>
<input type="email" class="form-control" name="email" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Description</label>
<textarea placeholder="Your text here.." name="description" class="form-control" rows="8" required></textarea>
<p class="help-block"></p>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
<input type="submit" value="Send" name="SubmitForm" class="btn btn-success btn-block btn-lg">
</form>
The problem was in the JavaScript file for the contact form. After removing this:
event.preventDefault(); // prevent default submit behaviour
The form is now working. Thanks all for the help :)

How do I display message on the same page?

I have a quick question about my form. After submitting the form you will be directed to a page followed by the text that I put in. The problem is that I want this text to be displayed on the same page as where the form is on (named contact.html) I use two files, one is the Mail_handler.php and the other contact.html. I've tried multiple things to fix it, but for some reason, I have no success. I hope that you guys can help me out! Below you can find the HTML and PHP.
<form method="POST" action="mail_handler.php">
<div class="col-sm-7 slideanim">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Naam" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="phone" name="phone" placeholder="Telefoonnummer" type="text" required>
</div>
<div class="col-sm-12 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control" id="msg" name="msg" placeholder="Bericht" rows="5"></textarea><br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" id="submit" name="submit" type="submit">Verstuur</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='infosyncdevelopment#gmail.com'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Bedankt voor uw bericht!"." ".$name.", Wij nemen zo snel mogelijk contact met u op.</h1>";
}
else{
echo "Something went wrong!";
}
}
?>
the best way is to use ajax, but if you may not do that, you can do this little trick:
change contact.html into php script (maybe contact.php)
<?php
if(isset($_GET['msg'])) echo $_GET['msg'];
?>
<form method="POST" action="mail_handler.php">
<div class="col-sm-7 slideanim">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Naam" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="phone" name="phone" placeholder="Telefoonnummer" type="text" required>
</div>
<div class="col-sm-12 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control" id="msg" name="msg" placeholder="Bericht" rows="5"></textarea><br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" id="submit" name="submit" type="submit">Verstuur</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
in the mail_handler.php, change echo to $msg
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='infosyncdevelopment#gmail.com'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
$msg = "<h1>Bedankt voor uw bericht!"." ".$name.", Wij nemen zo snel mogelijk contact met u op.</h1>";
}
else{
$msg = "Something went wrong!";
}
header("Location: contact.php?$msg");
} ?>
Use AJAX
$("form").submit(function(e) {
e.preventDefault();
var name = $('#name').val();
// do this for all other input tags
$.post("file.php" , {x:name , .....} , function(data){
// do stuff with data , here data is the things echoed/printed by 'file.php'
});
});

Categories