when a contact me script is run on my website, the script doesn't seem to be grabbing the POST variables from the HTML. The HTML is as follows:
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Contact Us</h2>
<h3 class="section-subheading text-muted">Fill out a form below to make an appointment, and our top masseur will be with you as soon as possible!</h3>
</div>
</div>
<!-- To Do: Change pictures, add FA's, finish "about",and remove portfolio-->
<div class="row">
<div class="col-lg-12">
<form name="sentMessage" id="contactForm" formaction="mail/contact_me.php" method="POST" novalidate>
<div class="row">
<div id="center><div class="col-md-6">
<center><div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" name="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Massage Type *" id="type" required data-validation-required-message="Please enter your type of massage.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Date of desired appointment *" id="message" required data-validation-required-message="Please enter the date">
<p class="help-block text-danger"></p>
</div>
</div>
<!--<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Please include date, and type of massage *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div> -->
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<button type="submit" class="btn btn-xl" formaction="mail/contact_me.php">Set Appointment!</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
The PHP Script (contact_me.php) is:
<?php
if(isset($_POST['submit'])){
$to = "*****"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "New Appointment!";
$subject2 = "Copy of your Appointment credentials.";
$message = $first_name . "'s Appointment. Phone: " . $phone . " Email: " . $_POST['email'] . " Type of Massage:" . "\n\n" . $_POST['type'] . " On:" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\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
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
I tried removing the isset (Or rather changing it to !isset), and the email sent. However, the credentials and the fields that were provided at the website were completely missing, and only the given text in the script was sent.
The attribute formaction is not valid. Use action instead.
In your case:
<form name="sentMessage" id="contactForm" action="mail/contact_me.php" method="POST" novalidate>
You're also missing a name attribute, as #anant kumar singh stated.
Related
For some odd reason, the business input value won't submit to the email... it's always blank.. can someone tell me what's wrong? Thank you!
<?php
// Check for empty fields
if(isset(empty($_POST['submit']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['business']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$business = strip_tags(htmlspecialchars($_POST['business']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'somekoreanguy#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nBusiness: $business\n\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
And here's my HTML:
<form name="sentMessage" id="contactForm" novalidate method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Business Name *" id="business" required data-validation-required-message="Please enter your business name.">
<p class="help-block text-danger"></p>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" name="submit" class="btn btn-xl">Send Message</button>
</div>
</div>
</form>
For some reason, when I put that "empty($_POST['business']) ||" in there, nothing comes in to the email. When I remove "type="text" from my business html section the email goes through but nothing as a value. it'll just say Business: and blank....
you did not define method="post"
<form name="sentMessage" id="contactForm" novalidate>
so it will be like
<form name="sentMessage" id="contactForm" novalidate method="post">
give name for
<button type="submit" name ="submit" class="btn btn-xl">Send Message</button>
So your code will be
if(isset($_POST['submit']){
//set your code here
}
It's always blank, because no name="" in your input form, name="" to reference form data after a form is submitted. Add name="" to your input like this..
<?php
// Check for empty fields
if(isset($_POST['submit'])) {
if(trim($_POST['email'])== '' || trim($_POST['phone'])== '' || trim($_POST['business'])== '' || trim($_POST['message'])== '' || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
}else{
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$business = strip_tags(htmlspecialchars($_POST['business']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'somekoreanguy#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nBusiness: $business\n\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
}
}
?>
<html>
<head>
</head>
<body>
<form name="contactForm" novalidate method="POST">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" name="name" id="name" data-validation-required-message="Please enter your name." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" name="email" id="email" data-validation-required-message="Please enter your email address." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" name="phone" id="phone" data-validation-required-message="Please enter your phone number." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Business Name *" name="business" id="business" data-validation-required-message="Please enter your business name." required>
<p class="help-block text-danger"></p>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" name="message" id="message" data-validation-required-message="Please enter a message." required></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div name="success"></div>
<button type="submit" name ="submit" class="btn btn-xl">Send Message</button>
</form>
</body>
</html>
Why is this form not working?
I'm creating a form that sends messages to users.
The user email comes from the database.
The query that searches the database is influenced by some data sent previously to the browser.
The problem at the moment is:
When one clicks to submit, nothing really happens.
Got a file called mini-contact.php with the following:
Script to proccess the form:
<?php
var_dump($_POST);
error_reporting(E_ALL);
$company=$_GET['company'];
$sql = "SELECT * FROM companies WHERE companies.companyID= '$company'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$companyemail = $row['Email_Address'];
if(isset($_POST['submit'])){
$to = "tiagomartinsperes#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = $_POST['subject'];
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$header = "From:" . $from;
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
$header2 = "From:" . $to;
$header2.= "MIME-Version: 1.0\r\n";
$header2.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header2.= "X-Priority: 1\r\n";
$status1 = mail($to,$subject,$message,$header);
$status2 = mail($from,$subject2,$message2,$header2); // sends a copy of the message to the sender
if($status1 and $status2){
$first_name = $_POST['first_name'];
echo 'Mail Sent. Thank you' . $first_name . ', we will contact you shortly.';
} else {
echo '<p>Something went wrong, Please try again!</p>';
}
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
}
?>
The actual form:
<form id="contact-form" method="post" action="">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>First Name *</label>
<input type="text" name="first_name" class="form-control" placeholder="Please enter your first name" required="required" data-error="First name is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Last Name *</label>
<input type="text" name="last_name" class="form-control" placeholder="Please enter your last name" required="required" data-error="Last name is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" placeholder="Please enter your email" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Phone</label>
<input type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 no-left-pad">
<div class="form-group">
<label>Subject</label>
<input type="text" name="subject" class="form-control" placeholder="Example: Service Request ">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 no-left-pad">
<div class="form-group">
<label>Message *</label>
<textarea name="message" class="form-control" placeholder="Please enter your message" rows="4" required="required" data-error=" Please enter your message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12 no-left-pad">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
<div class="col-md-12 no-left-pad">
<input type="submit" class="btn btn-default caps" name="submit" value="Submit">
</div>
</div>
</div>
</form>
What am I doing wrong?
Thank you for your time
One needs to have SMPT properly configure so that it works.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My contact form doesn't send messages.
There are no errors reported in validation so i get the "message sent", but message is not actually sent. So propably there is an error on configuring my mail settings
Here is my code:
HTML:
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading middle_heading">Contact Us</h2>
<div class="colored-line2"></div>
<p class="populer_des"></p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<form class="bg_field" name="sentMessage" action="./mail/validateform.php" method="post" id="contactForm" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl submit_message">Send Message</button>
</div>
</div>
</form>
</div>
</div>
</div>
PHP:
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$to = 'mail.ornithas.gr';
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From:mail.ornithas.gr\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
check your $to email address... it looks incorrect. So mail sending fail.
Header should be separated by '\r\n' not '\n' so header variable should be
$headers = "From: masudcsep#gmail.com\r\n";
$headers .= "Reply-To:
$email_address";
Check if the URL that you entered is correct:
<form class="bg_field" name="sentMessage" action="./mail/validateform.php" method="post" id="contactForm" novalidate>
this: ./mail/validateform.php means that you have a folder mail in your current directory which further has a file called: validateform.php .
check the filename
check the code in the file.
This bootstrap using html/php contact form sends me an email just fine, but without any of the users input information!
The email I received looks empty like this:
Name:
Email:
Subject:
Message:
The html for the form is:
<section id="partner">
<div class="container">
<div class="center wow fadeInDown">
<h2><br>Contact</h2>
<p class="lead">Send a general enquiry here or order your service here.</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The PHP for the form looks like this:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'heerschapnikki#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Why isn't it working properly? The message "thank you for contacting us" pops up fine and the email sends through, but non of the users information comes through.
Try to print the values you are sending. So use this:
var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...
Doing this, you will be able to see wether your fields are even posted correctly.
the fields have no id param. in the post you get the "id" nor the "name"
<label>Name *</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" id="email" class="form-control" required="required">
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Contact Me</h2>
<hr class="star-primary">
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<!-- To configure the contact form email address, go to mail/contact_me.php and update the email address in the PHP file on line 19. -->
<!-- The form should work on most web servers, but if the form is not working you may need to configure your web server differently. -->
<form name="sentMessage" id="contactForm" onsubmit="return validate()" action="contactme.php">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Email Address</label>
<input type="email" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Phone Number</label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<input type="submit" value="Submit" name="Submit" class="btn btn-success btn-lg"></input>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<-----PHP----->
<?php
if(empty($_POST['name']) ||
empty($_POST['emailz']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['emailz'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!!";
return false;
}
$name = $_POST['name'];
$email = $_POST['emailz'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from
$headers .= "Reply-To: $emailz";
$subject = 'New Message - Kieronb- $name';
$body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $emailz\n\nPhone: $phone\n\nMessage:\n$message";
mail("k#gmail.com",$subject,$body,$headers);
return true;
?>
SO, the above is the HTML and the PHP, now the majority of this code has been frankensteined from a bootstrap project, but i thought i would just have a play with the contact form too, but it is going all the way through to the missing arguments catch at the beginning of the PHP.
I cant see why the data is coming through empty- have i missed something painfully obvious?
I am running on a web server, not locally.
Thanks
Edit; thanks everyone, i forgot my method, and names on the form!
Your form fields do not have the name attribute. Without them their values are not submitted with the form.
<input type="email" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
should be
<input type="email" name="emailz" class="form-control" placeholder="Email Address" id="emailz" required data-validation-required-message="Please enter your email address.">
And your <form> needs to have the method specified as POST or else it defaults to GET:
<form method="post" name="sentMessage" id="contactForm" onsubmit="return validate()" action="contactme.php">