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
Related
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 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" ;
}
?>
The email I receive only shows the message, not the email address or phone number or even the name.
It also doesn't show from which email it has been sent.
I should receive whole information from the form, otherwise it wouldn't show me the message, I guess.
Maybe someone has more simple code than this one?
I tried but I'm stuck.
Can someone help me out?
Below is the HTML and PHP code
HTML Code:
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input id="name" class="form-control" placeholder="Name" type="text" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input id="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input id="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
PHP code:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$email_from = "$email";//<== update the email address
$email_subject = "New Form submission";
$email_phone = $phone;
$email_body = "You have received a new message from the user ".$name.
"\nHere is the message:\n ".$message.
"\nThe phone number:\n ".$phone.
"The email:\n ".$email.
$to = "info#czwebdesign.be";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: index.html');
?>
You also need to use name attribute for other fields as well same like message field, something like:
<input name="email" class="form-control" placeholder="Email" required>
<input name="name" class="form-control" placeholder="NAme" required>
<input name="phone" class="form-control" placeholder="Phone" required>
Otherwise you will get the Undefined Index warning in your script.
It's better to use php error_reporting() in your development mode, this will help to find out all errors and warnings in your code.
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
Try this
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input id="name" class="form-control" placeholder="Name" type="text" name="name" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input id="email" name="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input id="phone" name="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
Look here at the missing name="" attribute in your <input>
Use this code instead:
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input name="name" id="name" class="form-control" placeholder="Name" type="text" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input name="email" id="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input name="phone" id="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
i am having a problem in sending mail to my server. i dont know why the problem is occurring? everything is done perfect but it is not working maybe the fields are not filling properly and alert message is also not shown
if(isset($_POST['uname']) && isset($_POST['fname']) && isset($_POST['nic']) && isset($_POST['pecno'])&& isset($_POST['quality[25]'])&& isset($_POST['bday'])&& isset($_POST['quality[26]'])&& isset($_POST['postal'])&& isset($_POST['cell'])&& isset($_POST['houseno'])&& isset($_POST['mail'])&& isset($_POST['city'])&& isset($_POST['province'])&& isset($_POST['country']) )
{
$_Name = $_POST['uname'];
$_Fname = $_POST['fname'];
$_NIC = $_POST['nic'];
$_Pecno = $_POST['pecno'];
$_Gender = $_POST['quality[25]'];
$_Bday = $_POST['bday'];
$_Qualification = $_POST['quality[26]'];
$_Postal = $_POST['postal'];
$_Cell = $_POST['cell'];
$_Houseno = $_POST['houseno'];
$_Email = $_POST['mail'];
$_City = $_POST['city'];
$_Province = $_POST['province'];
$_Country = $_POST['country'];
if(!empty($_Name) && !empty($_Fname) && !empty($_NIC) && !empty($_Pecno)&& !empty($_Gender)&& !empty($_Bday)&& !empty($_Qualification)&& !empty($_Postal)&& !empty($_Cell)&& !empty($_Houseno)&& !empty($_Email)&& !empty($_City)&& !empty($_Province)&& !empty($_Country))
{
$to = 'info#mymail.com';
$subject = 'Join us mail';
$body = 'Sender Name : '.$_Name."\n".'Sender Father Name : '.$_Fname."\n".'Sender NIC : '.$_NIC."\n".'Sender PEC Number : '.$_Pecno."\n".'Sender Gender : '.$_Gender."\n".'Sender Birthday : '.$_Bday."\n".'Sender Qualification : '.$_Qualification."\n".'Sender Postal Address : '.$_Postal."\n".'Sender Cell Number : '.$_Cell."\n".'Sender House Number : '.$_Houseno."\n".'Sender Email : '.$_Email."\n".'Sender City : '.$_City."\n".'Sender Province : '.$_Province."\n".'Sender Country : '.$_Country;
$header = 'From : '.$_Email;
if(#mail($to, $subject, $body, $header))
{
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
}else
{
echo 'Please Try again in a few mints !';
}
}
}
html code
<form method="POST" action="index.php">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="uname" name="uname" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="fname" name="fname" placeholder="Father Name" type="text" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="nic" name="nic" placeholder="CNIC/Passport Number" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="pecno" name="pecno" placeholder="PEC Number" type="text">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="designation" name="designation" placeholder="Designation" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="organization" name="organization" placeholder="Organization" type="text">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
Gender: <div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" id="quality[25]" name="quality[25]" value="1" /> Male
</label>
<label class="btn btn-default">
<input type="radio" id="quality[25]" name="quality[25]" value="2" /> Female
</label>
</div>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" type="text" onfocus="(this.type='date')" id="bday" name="bday" placeholder="Date of Birth" ><br>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
Qualification: <div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="1" /> Bachelors In Engineering
</label>
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="2" /> Masters
</label>
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="3" /> PhD
</label>
</div>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="postal" name="postal" placeholder="Postal Address" type="text" >
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control slideanim" id="cell" name="cell" placeholder="Cell Number" type="tel" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="houseno" name="houseno" placeholder="House Number" type="tel" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control slideanim" id="mail" name="mail" placeholder="Email Address" type="email" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="city" name="city" placeholder="City" type="text" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="province" name="province" placeholder="Province/State" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="country" name="country" placeholder="Country" type="text" required>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right " type="submit">Send</button>
</div>
</div>
</div>
replace #mail with mail
if(#mail($to, $subject, $body, $header))
enable error reporting
error_reporting(E_ALL);
Show last error with:
print_r(error_get_last());
and check php_error.log for a problem
phpinfo();
for checking if mail module is enabled in php.
If all pass, check /var/log/mail about the messages, here could be 1001 issues with network, server, firewall etc...
hope it helps.
As you mentioned that same code is working perfectly on other page so please check it by removing "#" from mail as adding this will hide all notices and it will display error as well. Also try to print mail body text before mail function.
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>