i have used the submit image between the button tag to send the data on my mail id but when i clicked on button it redirect to next page without filled the data into text boxes and not getting the mail on my mail id. php script also used for this. i have checked many times but not get success so please help me out how to validate & send the data on mail. ican't under stand where is issue :
enter code here
<?php
if(isset($_POST['submit'])){
$to = "sandeepdoliya110@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'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$state = $_POST['state'];
$city = $_POST['city'];
$pincode = $_POST['pincode'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$payment_type = $_POST['payment_type'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . "
" . $last_name . "
" .$address1. "
" .$address2 . "
" . $state . "
" . $city . "
" . $pincode . "
" . $phone . "
" . $email . "
" . $payment_type ."
" ;
$message2 = "Thank you for showing interest. We will Contact You Soon " . $first_name . "
" . $last_name . "
" .$address1. "
" .$address2 . "
" . $state . "
" . $city . "
" . $pincode . "
" . $phone . "
" . $email . "
" . $payment_type ."
" ;
$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.
}
else{
echo "something is wrong";
}
?>
html part is :
<!-- Form -->
<form name="package-payment" id="package-payment" method="post" action="" class="form-horizontal">
<div class="form-group" id="error-message">
</div>
<div class="col-sm-12">
<div class="col-sm-6">
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label" required>First Name</label>
<div class="col-sm-9">
<input class="form-control" id="first_name" name="first_name" required name="first_name" value="" type="text">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Last Name</label>
<div class="col-sm-9">
<input class="form-control" id="last_name" name="last_name" required name="last_name" value="" type="text">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Address 1</label>
<div class="col-sm-9">
<input class="form-control" id="address1" name="address1" required name="address1" value="" type="text">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Address 2</label>
<div class="col-sm-9">
<input class="form-control" id="address2" name="address2"required name="address2" value="" type="text">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">State</label>
<div class="col-sm-9">
<select id="state" name="state" class="form-control">
<option value="State" option=""></option>
<option value="Andaman and Nicobar Islands">Andaman and Nicobar Islands</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Dadra and Nagar Haveli">Dadra and Nagar Haveli</option>
<option value="Daman and Diu">Daman and Diu</option>
<option value="Delhi">Delhi</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Lakshadweep">Lakshadweep</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Manipur">Manipur</option>
<option value="Meghalaya">Meghalaya</option>
<option value="Mizoram">Mizoram</option>
<option value="Nagaland">Nagaland</option>
<option value="Orissa">Orissa</option>
<option value="Pondicherry">Pondicherry</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Tripura">Tripura</option>
<option value="Uttaranchal">Uttaranchal</option>
<option value="Uttar Pradesh">Uttar Pradesh</option>
<option value="West Bengal">West Bengal</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">City</label>
<div class="col-sm-9">
<input class="form-control" id="city" name="city" required name="city" value="" type="text">
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Pincode</label>
<div class="col-sm-9">
<input class="form-control" id="pincode" name="pincode" required name="pincode" maxlength="6" value="" type="text">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Phone</label>
<div class="col-sm-9">
<input class="form-control" id="phone" name="phone" required name="phone" maxlength="12" value="" type="text">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input class="form-control" id="email" name="email" value="" type="text">
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Shipping</label>
<div class="col-sm-9">
<p class=" custom_form_fields_reeadonly"><b class="black-text"><i class="fas fa-rupee-sign"></i>. 199/-</b></p>
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Amount</label>
<div class="col-sm-9">
<p class=" custom_form_fields_reeadonly">MRP. <i class="fas fa-rupee-sign"></i>. <s>2,600/-</s> <b class="orange-text font-bolder">Offer <i class="fas fa-rupee-sign"></i>. 1,299/-</b></p>
</div>
</div>
<div class="form-group">
<label for="inputname" class="col-sm-3 control-label">Payment</label>
<div class="col-sm-9 padd-top-05em">
<input value="cod" name="payment_type" id="cod" checked="checked" type="radio"><b class="padd-right-1em"> Cash on Delivery</b>
<input value="prepaid" name="payment_type" id="prepaid" type="radio"><b> Prepaid</b>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<!-- <input name="gateway" type="hidden" id="gateway" />
<input type="hidden" name="ch" id="ch" value="" />
<input type="hidden" name="ssd" id="ssd" value=""/>
<input type="hidden" name="ocode" id="ocode" value=""/>
<input type="hidden" value="2922" id="page_id" name="page_id"/>
<input type="hidden" value="1498" id="amount" name="amount"/>
<input type="hidden" value="1498" id="payu_amount" name="payu_amount"/>
<input type="hidden" value="25" id="product_id" name="product_id"/>
<input type="hidden" value="fitband" id="product_info" name="product_info"/>-->
<div class="col-sm-12 text-center">
<button type="button" onclick="location.href = 'contact.php';" name="submit" value="submit" class="submitbtn">
<img src="images/button-buy-now.png" alt="submit" style="padding:18px 0px; width:190px;">
</button>
<span class="brand-color"><b>Mail Us:</b></span><i class="font-bolder">support@neutrikart.com</i>
</div>
</form>
<!-- Icons -->
<div class="col-sm-12 icon-form-box black-text text-uppercase text-shadow-black">
<div class="col-sm-3 padd-top-1em">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="icon-number font-bolder">100%</td>
<td>risk-free purchase</td>
</tr>
</table>
</div>
<div class="col-sm-3 icon-number-top padd-top-1em">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="icon-number font-bolder">COD</td>
<td>cash-on delivery</td>
</tr>
</table>
</div>
<div class="col-sm-3 icon-number-top padd-top-1em">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="icon-number font-bolder">48-Hrs</td>
<td>money-back guarantee</td>
</tr>
</table>
</div>
<div class="col-sm-3 icon-number-top padd-top-1em animated fadeInDown">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="icon-number font-bolder">50%</td>
<td>Discounted Price</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Since you are submitting to same page, remove the
action=""
on your form.
Change submit button type from type="button" To type="submit"