contact form not getting submitted - php

On clicking the submit button it is showing submit is not set after the if condition. I guess this message is showing because the form is not getting submitted. I don't know where I'm going wrong kindly help me fix this issue. I'm herewith attaching a part of my contact.php code and 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>
<input class="btn btn-primary solid blank button" id="btn" type="submit" value="submit" name="submit">
</div>
</form>
mail.php
<?php
if (isset($_POST['email'])){
echo "submit is set to {$_POST['submit']} and now we send the email<br>";
$to = "abc#email.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";
header('Location: https://imatrixautomation.com/contact.php');
exit;
?>

nothing wrong with your code, i guess you doing a direct request to mail.php
try this code, maybe this help your problem
<?php
if($_POST){ // add condition if http request is POST then process your POST request
if (isset($_POST['email'])){
echo "submit is set to {$_POST['submit']} and now we send the email<br>";
$to = "abc#email.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; // if POST process has done, script will stop, and code above will not showing
}
?>
<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>
<input class="btn btn-primary solid blank button" id="btn" type="submit" value="submit" name="submit">
</div>
</form>

Related

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>

linking contact form to an email HTML/PHP

I'm trying to make the Contact us form working,
P.S. I'm not a Developer, my coding skills is very limited.
this is the HTML code: (from a template with some adjustments)
<!--Contact Starts -->
<div class="container contactform center">
<h2 class="text-center wowload fadeInUp">Get in touch</h2>
<div class="row wowload fadeInLeftBig">
<div class="col-sm-6 col-sm-offset-3 col-xs-12">
<input type="text" placeholder="Name">
<input type="text" placeholder="Company">
<input type="text" placeholder="Email">
<input type="text" placeholder="Subject">
<textarea rows="5" placeholder="Message"></textarea>
<button class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>
</div>
</div>
and this is the PHP script: (wrote it myself)
$name = $_POST['Name'] ;
$from = $_POST['Email'] ;
$message = $_POST['Message'] ;
$to = "contact#mywebsite.com" ;
$subject = "Website Contact Form" ;
mail ($to, $subject, $message, "From: " . $name . $company . $email) ;
echo "Your Message Has Been Sent" ;
I'm not sure what I did wrong, but it's not workign.
the php file called emailscript.php located at /assets/php/emailscript.php
right now I'm getting an error this error: "Not Found
The requested document was not found on this server."
try to this...
<!--Contact Starts -->
<div class="container contactform center">
<h2 class="text-center wowload fadeInUp">Get in touch</h2>
<div class="row wowload fadeInLeftBig">
<div class="col-sm-6 col-sm-offset-3 col-xs-12">
<form action="/assets/php/emailscript.php" method="post">
<input type="text" placeholder="Name" name="Name">
<input type="text" placeholder="Company" name="Company">
<input type="text" placeholder="Email" name="Email">
<input type="text" placeholder="Subject" name="Subject">
<textarea rows="5" placeholder="Message" name="Message"></textarea>
<button type="submit" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>
</form>
</div>
</div>
Please put your form elements in <form> tag. And give each element a name attribute.by using name attribute we will get form data in php.
<form name="contact" action="/assets/php/emailscript.php" method="POST">
<input type="text" placeholder="Name" name="contact_name">
<input type="text" placeholder="Company" name="company">
<input type="text" placeholder="Email" name="email">
<input type="text" placeholder="Subject" name="subject">
<textarea rows="5" placeholder="Message" name="message"></textarea>
<button class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>
</form>
Encircle your code in isset function to avoid any error
<?php
if(isset($_POST['Name']))
{
$name=$_POST['Name'] ;
$from=$_POST['Email'] ;
$message=$_POST['Message'] ;
$to="contact#mywebsite.com" ;
$subject="Website Contact Form" ;
mail ($to, $subject, $message, "From: " . $name . $company . $email) ;
// it echo not eco
echo "Your Message Has Been Sent" ;
}
?>

PHP form doesn't send mail – just reloads page

I have a problem with my contact form. When I click the send button it just refreshes the page and doesn't send the mail. I tried so many things but couldn't find a solution. I hope somebody can help me.
Here is the php and contact part:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$body ="From: $name\n E-Mail: $email\n Message:\n $message";
$mail = mail('mymail#gmail.com', $subject, $body);
if ($mail==true)
{
header ("Location: index.php?success=1#contact");
}
else
{
header ("Location: index.php?success=2#contact" );
}
}
?>
....
<form id="contact-form">
<div class="row">
<div class="col-md-6">
<form class="form-horizontal" method="post" role="form" action="index.php">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required="required" />
</div>
<div class="form-group">
<label for="email">
Email Address</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required="required" />
</div>
</div>
<div class="form-group">
<label for="subject">
Subject</label>
<select id="subject" name="subject" class="form-control" required="required">
<option value="na" selected="">Choose One:</option>
<option value="service">General Question</option>
<option value="suggestions">Suggestions</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="name">
Message</label>
<textarea id="message" name="message" class="form-control" rows="9" cols="25" required="required" placeholder="CONTACT FORM UNDER CONSTRUCTION! PLEASE USE THE ADRESS AT THE RIGHT/DOWN BELOW."></textarea>
</div>
</div>
<div class="col-md-12">
<input type="submit" name="submit" value="SEND" class="btn btn-skin pull-right" id="btnContactUs">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php if($_GET['success'] == 1)
{
echo "Thank you. Your message was sent!";
}
elseif ($_GET['success'] == 2)
{
echo "Sorry, but there were error(s) found with the form you submitted. <br/>Please try again.";
}
?>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
The problem is that you have a form tag inside another form tag.
Try to change the form tag what have the id contact-form to a div tag.

Unable to receive email from simple ajax php contact

Hi I'm trying develop a simple contact form in php. I have done a lot of research but can't seem to solve this.
Here is the HTML code:
<form id="contact-form" action="contact.php" method="post" class="clearfix">
<div class="contact-box-hide">
<div class="col-sm-6">
<input type="text" class="form-control" id="first_name" name="first_name" required placeholder="First Name">
<span class="first-name-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="last_name" name="last_name" required placeholder="Last Name">
<span class="last-name-error"></span>
</div>
<div class="col-sm-6">
<input type="email" class="form-control" id="contact_email" name="contact_email" required placeholder="Email Address">
<span class="contact-email-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="subject" name="contact_subject" required placeholder="Subject">
<span class="contact-subject-error"></span>
</div>
<div class="col-sm-10">
<textarea class="form-control" rows="5" id="message" name="message" required placeholder="Message"></textarea>
<span class="contact-message-error"></span>
</div>
<div class="col-sm-2">
<button id="contact-submit" class="btn custom-btn col-xs-12" type="submit" name="submit"><i class="fa fa-rocket"></i></button>
<span id="contact-loading" class="btn custom-btn col-xs-12"> <i class="fa fa-refresh fa-spin"></i> </span>
</div>
</div><!-- /.contact-box-hide -->
<div class="contact-message"></div>
</form><!-- /#contact-form -->
And this is the PHP portion:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$contact_email = $_POST['contact_email'];
$contact_subject = $_POST['contact_subject'];
$message = $_POST['message'];
$subject = "New Message from Website Form";
$submit = $_POST['submit'];
if($submit){
//Prepare Email
$from = 'From: My Website'."\r\n";
$to = 'odeleon#outlook.com';
$subject = "Message from United Passions for Christ.org";
$body = "".
"From: ".$first_name."\n".
"E-mail: ".$contact_email."\n".
"Message: ".$message."\n";
//Send email
if(mail($to, $subject, $body, $from)){
echo '<p>Your message has been sent!</p>';
}
}
?>
he contact form shows up OK and there aren't any php errors when the user hits submit. However the email never appears in my inbox. Any ideas?
Is there something that I'm missing from this?
Check php.ini file configuration, you can find that in /etc/ directory.
Refer this http://www.tutorialspoint.com/php/php_sending_emails.htm
Try
if(isset($_POST['submit'])){
//your code to submit
}

PHP contact form not working right

I've been working on a contact form. I have added used the POST method to send it to a set email address. It doesn't seem to be working though. It just runs and stops as if the code is broken. The HTML and PHP are below.
<form action="contact-form.php" method="post" id="contact-form" name="contact-form">
<div class="form-group">
<label for="name">Your name</label> <input class=
"form-control" id="name" name="name" type="text">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input class="form-control" id="email" name="email"
type="email">
</div>
<div class="form-group">
<label for="phone">Phone</label> <input class=
"form-control" id="phone" name="phone" type="text">
</div>
<div class="form-group">
<label for="message">Your message</label>
<textarea class="form-control" id="message" name=
"message" rows="6">
</textarea>
</div>
<div class="submit">
<input class="button button-small" type="submit"
value="Send">
</div>
</form>
<?php
if(isset($_POST['submit'])) {
$to = "gfrazer#hotmail.co.uk";
$from = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$message = $name . " " . " wrote the following: " . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
header('Location: http://www.google.co.uk');
}
?>
You need to add a name to your submit button. From your snippit, you have no $_POST['submit']:
<form action="contact-form.php" method="post" id="contact-form" name="contact-form">
<div class="form-group">
<label for="email">Email address</label>
<input class="form-control" id="email" name="email" type="email">
</div>
<div class="form-group">
<label for="phone">Phone</label> <input class="form-control" id="phone" name="phone" type="text">
</div>
<div class="form-group">
<label for="message">Your message</label>
<textarea class="form-control" id="message" name="message" rows="6"></textarea>
</div>
<div class="submit">
<!-- ADD name="submit" -->
<input name="submit" class="button button-small" type="submit" value="Send" />
</div>
</form>

Categories