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" ;
}
?>
Related
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>
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>
I'm trying to check if the form has been submitted. If I press the submit button, the success message will appear but when I check my mailbox I don't see any message. I'm using WampServer. I followed a YouTube tutorial where the guy has the exact same code but for some reason, it doesn't work for me.
<form action="contact.php" method="post" id="myForm">
<div class="md-form">
<i class="fas fa-user prefix grey-text"></i>
<input type="text" required name="name" id="form_name" class="form-control" />
<label for="form_name">Your name</label>
</div>
<div class="md-form">
<i class="fas fa-envelope prefix grey-text"></i>
<input type="email" required name="email" id="form_email" class="form-control" />
<label for="form_email">Your email</label>
</div>
<div class="md-form">
<i class="fas fa-tag prefix grey-text"></i>
<input type="text" name="subject" required id="form-Subject" class="form-control" />
<label for="form_subject">Subject</label>
</div>
<div class="md-form">
<i class="fas fa-pencil-alt prefix grey-text"></i>
<textarea id="form_text" name="message" class="form-control md-textarea" rows="3"></textarea>
<label for="form_text">Your message</label>
</div>
<div class="text-center mt-4">
<button class="btn contact-button text-white" type="submit" name="submit">Submit</button>
</div>
<div id="success_message" class="text-dark text-center"></div>
</form>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "patriciushorny#gmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an e-mail from ".$name.".\n\n".$message;
mail($mailFrom, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
?>
<form class="form-area contact-form text-right" action="mail.php" method="post">
<div class="row">
<div class="col-lg-6 form-group">
<input name="name" id="name" placeholder="Enter your name" class="common-input mb-20 form-control" type="text">
<input name="email" id="email" placeholder="Enter email address" class="common-input mb-20 form-control" type="email">
<input name="sub" id="sub" placeholder="Enter subject" class="common-input mb-20 form-control" type="text">
</div>
<div class="col-lg-6 form-group">
<textarea class="common-textarea form-control" name="desc" id="desc" placeholder="Enter Messege" ></textarea>
</div>
<div class="col-lg-12">
<button class="genric-btn primary" value="submit" id="submit" name="submit" style="float: right;">Send Message</button>
</div>
</div>
More Details view this link VIEW FULL CODE
I am trying send an email through my contact form, here is my php code:
if(isset($_POST['send'])) {
$fn = $_POST['firstname'];
$ln = $_POST['lastname'];
$name = $fn . ' ' . $ln;
$email = $_POST['email'];
$message = $_POST['comment'];
$subject = $_POST['subject'];
$to = "iesteghlal#gmail.com";
$header = "From: $email \r\n";
$send_contact = mail($to, $subject, $message, $header);
if($send_contact){
echo "We've recived your contact information";
echo "Your email has been sent. Stay in touch with us.";
echo $name;
echo $email;
echo $message;
echo $subject;
echo $mailheader;
echo $body;
echo "</br><a href='index.html'> Go Back. </a>";
}
else {
echo "something not working";
}
}
else {
echo "Something wrong.";
}
when I press send, it goes to the next page and it gives me "something not working" error. I am not quite sure what is going wrong here.
this is my contact form:
<form role="form" action="send.php" method="post" accept-charset="utf-8">
<div class="modal-body" style="padding: 5px; background-color:#D7D1D1;">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6" style="padding-bottom: 10px;">
<input class="form-control" id="firstname" name="firstname" placeholder="Firstname" required="" autofocus="" type="text">
</div>
<div class="col-lg-6 col-md-6 col-sm-6" style="padding-bottom: 10px;">
<input class="form-control" id="lastname" name="lastname" placeholder="Lastname" required="" type="text">
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12" style="padding-bottom: 10px;">
<input class="form-control" id="email" name="email" placeholder="E-mail" required="" type="text">
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12" style="padding-bottom: 10px;">
<input class="form-control" id="subject" name="subject" placeholder="Subject" required="" type="text">
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<textarea style="resize:vertical;" class="form-control" placeholder="Message..." rows="6" id="comment" name="comment" required=""></textarea>
</div>
</div>
</div>
<div class="panel-footer">
<input class="btn btn-success" value="Send" type="submit" id="submit" name="send">
<!--<span class="glyphicon glyphicon-ok"></span>-->
<input class="btn btn-danger" value="Clear" type="reset">
<!--<span class="glyphicon glyphicon-remove"></span>-->
<button style="float: right;" type="button" class="btn btn-default btn-close" data-dismiss="modal">Close</button>
</div>
</form>
what is going wrong?
Are you using a live test server for this or are you using the likes of an offline server such as Apache? If you are using an offline server the email will not send unless you have setup utilities to do so.
This is not an answer, but due to a lack of 50 rep I cannot comment.
EDIT
Suggestion of an auto-redirect after the post has been sent, rather than a manual link.
<script type="text/javascript">
setTimeout('Redirect()', 5000)
function Redirect() {
location.href='contact.php'
}
</script>
Something like this can work, by adding to your existing code.
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>