<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">
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm building a site, and am having problems with the php form. I have looked through and cannot find anything that I see as wrong. However, I am also not very proficient with PHP and have never created a form like this before. Thank you very much if you can help.
Here is the code:
PHP:
<?php
$company = $_POST['company'];
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$numberofvehicles = $_POST['numofvehicles'];
$date= $_POST['date'];
$time = $_POST['time'];
$address = $_POST['address'];
$to = 'email#email.com';
$subject = "GPS Form Request: $company\n";
$body = "From: $name\n E-Mail: $email\n Company:\n $company Phone: $phone\n Date: $date\n Time: $time\n Address: $address\n Number of Vehicles: $numberofvehicles\n";
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if(isset($_POST['submit']){
mail ($to, $subject, $body, $headers); //mail sends it to the SMTP server side which sends the email
echo "<p>Your message has been sent!</p>";
}
else {
echo "<p>Something went wrong, go back and try again!</p>";
}
?>
HTML:
<form id="contact-form" method="post" action="/php/email.php" role="form">
<fieldset>
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="company_name">Your Company's Name</label>
<input id="company_name" type="text" name="company" class="form-control" placeholder="Please enter your company's name *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="your_name">Your Name</label>
<input id="your_name" type="text" name="name" class="form-control" placeholder="Please enter your first and last name *" required="required" data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_email">Preferred Email</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your preferred email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_phone">Preferred Phone</label>
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your preferred phone number">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="vehicles_number">Number of Vehicles</label>
<input id="vehicles_number" type="text" name="numofvehicles" class="form-control" placeholder="How many vehicles for installation?">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="install_address">Installation Address</label>
<input id="input_address" type="text" name="address" class="form-control" placeholder="What is the installation address?">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="install_date">Choose a Date for Installation</label>
<input id="calendar" name="date" type="text" class="form-control" placeholder="Please choose a date for installation" >
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="install_time">Choose a Time for Installation</label>
<input id="install_time" type="time" name="phone" class="form-control" placeholder="Please choose a time for installation">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
</fieldset>
<fieldset>
<div class="col-md-12">
<input type="submit" id="submit" name="submit" class="btn btn-success btn-send" value="Send message">
</div>
</div>
</div>
</div>
</fieldset>
</form>
</container>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script>
$('#calendar').datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
});
</script>
</body>
</div>
You are missing a closing parenthesis bracket in your php if statement.
if(isset($_POST['submit']))
At the very end of that statement ^
i have a static one page site, with two forms, that i want to extract the information of the fields of that forms then send it to my email
this is the code of the two forms:
my exact question is how can i creat a php page that can help me to handle the two forms and receive the info in my email
<!-- Reservation Section -->
<section id="reservation">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Reserve Your Tour</h2>
<h3 class="section-subheading ">Explore in Our <a class="page-scroll" href="#portfolio">Tours Secetion</a>, Make Your Mind, Make Your Reservation.</h3>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<form name="sentMessage" 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="name2" 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="email2" 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="phone2" 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="Your Country *" id="country" required data-validation-required-message="Please enter your country .">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Number Of People *" id="number" required data-validation-required-message="Please enter The number of people your comming with.">
<p class="help-block text-danger"></p>
</div>
</div>
<!-- second half !!-->
<div class="col-md-6">
<div class="form-group">
<input type="tel" class="form-control" placeholder="Date of arrival *(MM/DD/YYY)" id="dateofarrival" required data-validation-required-message="Please enter your Arrival Date.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Date of departure * *(MM/DD/YYY)" id="dateofdeparture" required data-validation-required-message="Please enter your Date of departure *.">
<p class="help-block text-danger"></p>
</div>
<div class="checkbox checkbox-inline">
<label><input type="checkbox" value="ToursFatima4Days" required data-validation-required-message="Please chose one tour at least">-Tours Fatima 4 Days</label>
<label><input type="checkbox" value="ToursAicha5Days">-Tours Aicha 5 Days </label>
<label><input type="checkbox" value="ToursAssmae9Days">-Tours Assmae 9 Days</label>
<label><input type="checkbox" value="ToursZaina5Days">-Tours Zaina 5 Days</label>
<label><input type="checkbox" value="AdventuresSafaris">-Adventures Safaris</label>
</div>
<br><br>
<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 Reservation</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section> <!-- end Reservation seccession -->
<!-- Contact Section -->
<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">Let Us Know About Anything Going on Your Mind.</h3>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<form name="sentMessage" id="contactForm" method="post" action="mail/contact_me.php" <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> 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">Send Message</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
You're looking for PHP's mail function. There's also mail scripts that you can use.
Check these out:
http://www.inmotionhosting.com/support/edu/website-design/using-php-and-mysql/how-to-create-a-custom-php-contact-form
http://www.inmotionhosting.com/support/email/send-email-from-a-page/using-phpmailer-to-send-mail-through-php
I am fairly new to bootstrap and this is the first I have used reCaptcha. I also don't have a lot of experience with PHP. I have designed numerous web sites and am very familiar with html(5) and css(3).
I can easily add the reCaptcha widget to my form and it displays correctly. However, I have no clue how to update my PHP file for the server side processing. Below is the code for my bootstrap contact form section and the code for my PHP file.
HTML (contact section):
<!-- Contact Section -->
<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">
<form name="sentMessage" id="contactForm" novalidate>
<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="email" 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 class="g-recaptcha" data-sitekey="mySitekey"></div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
PHP (where do I put the required server-side php code here?):
<?php
// Check for empty fields
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'];
// Create the email and send the message
$to = 'myEmail'; // This is where the form will send a message to.
$email_subject = "Portfolio Website Message: $name";
$email_body = "You have received a new message from your portfolio 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: noreply#mydomain.com\n"; // This is the email address the generated message will be from.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Thanks for your help!
I am fairly new to bootstrap. I have a contact form that is working properly. However, I would like to add a captcha to the form to help eliminate unwanted SPAM mail. How can I add a captcha to my existing form or any other "are you human" option to the form (i.e. would a simple checkbox work) and make it responsive as the current form is? Below is the code for my form:
<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">
<form name="sentMessage" id="contactForm" novalidate>
<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="email" 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">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
Google ReCaptcha is a great tool for this and Google is also preparing a Captcha where no user input would be needed.
To implement a ReCaptcha, you will need to do following:
Create Google ReCaptcha API key
Paste the code into your HTML. Basically a div and some JS.
Validate the response when the form is submitted.
You can follow the step-by-step tutorial here: https://bootstrapious.com/p/bootstrap-recaptcha.
This is the php file I have made to store the responses from the Contact page of my Html file which is also written at the end.
Even after submitting the data in the contact field I am not getting anything.
Please try to help me out with the error.
PHP Code
<?php
// Check for empty fields
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'];
// Create the email and send the message
$to = 'abcd#gmail.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\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
HTML CODE
<form name="sentMessage" id="contactForm" novalidate>
<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="email" 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">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
You are missing the method and name attributes.
You are not specifying the Form method . If you want to use post method, you should specify
method="post".
If you are not specifying the form method, the default method will be GET
Also, you should add the attribute name to each and every input fields, then only you can access those in post.
Your updated HTML code will be:
<form name="sentMessage" id="contactForm" novalidate method="post">
<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" name="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="email" name="email" 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" name="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" name="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">
<button type="submit" name="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
Look the method attribute in form and name attribute in input fields.
Hope this helps