I have this html code for the form:
<form action="index.php" method="post" id="form" class="form" role="form">
<h4 class="form-heading">Luxury at an affordable price</h4>
<div class="form-validation alert"></div>
<div class="form-group">
<label for="form-name">Name</label>
<input type="text" name="name" id="form-name" class="form-control" placeholder="Your Full Name" autocomplete="off">
</div>
<div class="form-group">
<label for="form-email">Email Address</label>
<input type="email" name="email" id="form-email" class="form-control" placeholder="Your Valid Email Address" autocomplete="off">
</div>
<div class="form-group">
<label for="form-phone">Phone Number</label>
<input type="phone" name="phone" id="form-phone" class="form-control" placeholder="Your Valid Phone Number" autocomplete="off">
</div>
<div class="form-group">
<label for="form-info">Package</label>
<p>
<select type="info" name="info" id="form-info" class="form-control">
<option value="Diamond">Diamond</option>
<option value="Gold">Gold</option>
<option value="silver">Silver</option>
<option value="silver">Custom</option>
</select>
</p>
</div>
<div class="form-group">
<label for="form-pax"># of People</label>
<input type="pax" name="pax" id="form-pax" class="form-control" placeholder="Number of People in your Party" autocomplete="off">
</div>
<div class="form-group">
<label for="form-com">Comments</label>
<input type="com" name="com" id="form-com" class="form-control" placeholder="Additional Comments" autocomplete="off">
</div>
<div class="form-group form-group-submit">
<button class="btn btn-primary btn-lg btn-block" data-loading-text="Action Button">More Info</button>
</div>
</form>
And also i have this Php code:
<?php
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['info']) ||
empty($_POST['pax']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo '<script type="text/javascript">alert("Your data is not valid!");</script>';
return false;
}
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$info = $_POST['info'];
$pax= $_POST['pax'];
$com= $_POST['com'];
// Create the email and send the message
$to = 'rubengallardo.88#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Contacto de cancunprivateparty.com : $name";
$email_body = "Nuevo mensaje del formulario de Cancún Private Party.\n\n"."Estos son los detalles:\n\nNombre: $name\n\nEmail: $email\n\nTel: $phone\n\nPaquete: $info \n\n # de Pax: $pax \n\n Comentarios: $com" ;
$headers = "From: noreply#cancunprivateparty.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.\n\n Comentarios: $com
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
echo '<script type="text/javascript">alert("Your message has been sent!");</script>';
echo '<meta http-equiv="refresh" content="0; URL=http://www.cancunprivateparty.com">';
return true;
?>
When i fill the form and send the email i get a error that says "your data is not valid" even if my data is valid.
What could be the problem here?
is your <form> tag missing?
Works fine for me when set:
contact.html
<form method="post" action="contact_form.php">
<h4 class="form-heading">Luxury at an affordable price</h4>
<div class="form-validation alert"></div>
<div class="form-group">
<label for="form-name">Name</label>
<input type="text" name="name" id="form-name" class="form-control" placeholder="Your Full Name" autocomplete="off">
</div>
<div class="form-group">
<label for="form-email">Email Address</label>
<input type="email" name="email" id="form-email" class="form-control" placeholder="Your Valid Email Address" autocomplete="off">
</div>
<div class="form-group">
<label for="form-phone">Phone Number</label>
<input type="phone" name="phone" id="form-phone" class="form-control" placeholder="Your Valid Phone Number" autocomplete="off">
</div>
<div class="form-group">
<label for="form-info">Package</label>
<p>
<select type="info" name="info" id="form-info" class="form-control">
<option value="Diamond">Diamond</option>
<option value="Gold">Gold</option>
<option value="silver">Silver</option>
<option value="silver">Custom</option>
</select>
</p>
</div>
<div class="form-group">
<label for="form-pax"># of People</label>
<input type="pax" name="pax" id="form-pax" class="form-control" placeholder="Number of People in your Party" autocomplete="off">
</div>
<div class="form-group">
<label for="form-com">Comments</label>
<input type="com" name="com" id="form-com" class="form-control" placeholder="Additional Comments" autocomplete="off">
</div>
<div class="form-group form-group-submit">
<button class="btn btn-primary btn-lg btn-block" data-loading-text="Action Button">More Info</button>
</div>
</form>
contact_form.php
<?php
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['info']) ||
empty($_POST['pax']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo '<script type="text/javascript">alert("Your data is not valid!");</script>';
return false;
}
echo "yes";
return true;
?>
Related
This has been bugging me all day and I've given up trying to figure it out for myself, but the answer's probably really obvious...
My contact form works fine, however I don't receive input for all fields. I only get name, phone, email and message. I've given the form fields a name attribute so I'm not sure what's happening.
Here is the HTML:
<form name="sentMessage" id="contactForm" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="name" class="form-control" placeholder="Your Name *" name="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="phone" class="form-control" placeholder="Your Phone Number *" name="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="email" class="form-control" placeholder="Your Email *" name="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="text" class="form-control" name="suburb" placeholder="Your Suburb *" id="suburb" required data-validation-required-message="Please enter your address.">
<p class="help-block text-danger"></p>
</div>
<div class="select">
<div class="col-sm-6">
<div class="form-group">
<select class="selectpicker" name="state" id="state" data-width="100%" data-height="100%" title="Choose State *" data-style="btn-primary">
<option>QLD</option>
<option>NSW</option>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-sm-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Post Code *" name="postcode" id="postcode" required data-validation-required-message="Please enter your post code.">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product1" id="product1" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity1" id="quantity1">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product2" id="product2" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity2" id="quantity2">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="select">
<div class="col-xs-6">
<div class="form-group">
<select class="selectpicker" name="product3" id="product3" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
<optgroup label="100 Series">
<option>90mm Grey Standard</option>
</optgroup>
</select>
</div>
</div>
</div>
<div class="right-form-column">
<div class="col-xs-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Quantity" name="quantity3" id="quantity3">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="form-group">
<textarea class="form-control" placeholder="Additional comments" name="message" id="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" name="submit">submit</button>
</div>
</div>
</form>
And the PHP:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'myname#mydomain.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "P Services Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details: From: $name\n Phone: $phone\n E-Mail: $email_address\n Suburb: $suburb\n State: $state\n Post Code: $postcode\n Product: $product1\n Quantity: $quantity1\n Product: $product2\n Quantity: $quantity2\n Product: $product3\n Quantity: $quantity3\n Message:\n $message";
$headers = "From: noreply#yourdomain.com\n";
$headers .= "Reply-To: $email_address";
if(mail($to,$email_subject,$email_body,$headers)){
echo "Mail sent successfully.";
}
else{ echo "Error.";
}
?>
make sure that, you've removed disabled tag in html elemets.
THIS IS WRONG. PHP WON'T RECOGONIZE YOUR ELEMENT.
<input type="text" disabled>
INSTED OF USING disabled you can use readonly.
THIS IS THE CORRECT METHORD
<input type="text" readonly>
Your code returns all the information for me
All i did was change the form method so all the data is being passed its just needs to be handled correctly in your PHP
The only thing you need to change is specify the method of form submission (POST or GET).
Either use
<form name="sentMessage" id="contactForm" novalidate method="POST">
OR
Access the form variables using $_GET like $_GET['name'])
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 have a problem with my contact form. When I click the send button it just refreshes the page and doesn't send the mail. I tried so many things but couldn't find a solution. I hope somebody can help me.
Here is the php and contact part:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$body ="From: $name\n E-Mail: $email\n Message:\n $message";
$mail = mail('mymail#gmail.com', $subject, $body);
if ($mail==true)
{
header ("Location: index.php?success=1#contact");
}
else
{
header ("Location: index.php?success=2#contact" );
}
}
?>
....
<form id="contact-form">
<div class="row">
<div class="col-md-6">
<form class="form-horizontal" method="post" role="form" action="index.php">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required="required" />
</div>
<div class="form-group">
<label for="email">
Email Address</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required="required" />
</div>
</div>
<div class="form-group">
<label for="subject">
Subject</label>
<select id="subject" name="subject" class="form-control" required="required">
<option value="na" selected="">Choose One:</option>
<option value="service">General Question</option>
<option value="suggestions">Suggestions</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="name">
Message</label>
<textarea id="message" name="message" class="form-control" rows="9" cols="25" required="required" placeholder="CONTACT FORM UNDER CONSTRUCTION! PLEASE USE THE ADRESS AT THE RIGHT/DOWN BELOW."></textarea>
</div>
</div>
<div class="col-md-12">
<input type="submit" name="submit" value="SEND" class="btn btn-skin pull-right" id="btnContactUs">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php if($_GET['success'] == 1)
{
echo "Thank you. Your message was sent!";
}
elseif ($_GET['success'] == 2)
{
echo "Sorry, but there were error(s) found with the form you submitted. <br/>Please try again.";
}
?>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
The problem is that you have a form tag inside another form tag.
Try to change the form tag what have the id contact-form to a div tag.
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>
I am trying to tie my html form to a PHP mailer and for some reason the form inputs are not storing in my variables. I have tried searching all over and I cannot see what I am doing wrong. Any help would be greatly appreciated.
Form handler:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$date = trim($_POST["date"]);
$guests = trim($_POST["guests"]);
$description = trim($_POST["description"]);
}
Form:
<form role="form" class="text-center" method="POST" enctype="text/plain" action="index.php">
<div class="form-group">
<label for="name">Nombre</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Correo Electrónico</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="date">Fecha del Evento</label>
<input type="date" id="date" class="form-control" name="date">
</div>
<div class="form-group">
<label for="guests">Número de Huéspedes</label>
<select class="form-control" id="guests" name="guests">
<option>1 - 2</option>
<option>3 - 4</option>
<option>5 - 6</option>
<option>7 - 8</option>
</select>
</div>
<div class="form-group">
<label for="description">Descripción de Evento</label>
<textarea class="form-control" id="description" rows="3" name="description"></textarea>
</div>
<div style="display: none;">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" name="address">
</div>
<input type="submit" class="btn btn-default" value="Enviar">
</form>
For PHP text/plain is not a valid value for enctype in <form>
Take a look here