PHP form sending blank data

Hi

I keep receiving blank emails through my contact us form even after applying CAPTCHA. You can find the is

For contact.php

			<div id="message-contact"></div>
			<form method="post" action="mail-contact.php">
				<div class="row">
					<div class="col-md-6 col-sm-6">
						<div class="form-group">
							<label>First Name</label>
							<input type="text" class="form-control required" id="name_contact" name="name_contact" placeholder="First Name" required>
						</div>
					</div>
					<div class="col-md-6 col-sm-6">
						<div class="form-group">
							<label>Last Name</label>
							<input type="text" class="form-control required" id="lastname_contact" name="lastname_contact" placeholder="Last Name" required>
						</div>
					</div>
				</div>
				<!-- End row -->
				<div class="row">
					<div class="col-md-6 col-sm-6">
						<div class="form-group">
							<label>Email</label>
							<input type="email" id="email_contact required" name="email_contact" class="form-control" placeholder="Email-ID" required>
						</div>
					</div>
					<div class="col-md-6 col-sm-6">
						<div class="form-group">
							<label>Phone</label>
							<input type="text" id="phone_contact required" name="phone_contact" class="form-control" placeholder="Phone number" required>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-md-12">
						<div class="form-group">
							<label>Message</label>
							<textarea rows="5" id="message_contact required" name="message_contact" class="form-control" placeholder="Write your message" style="height:200px;"></textarea>
						</div>
					</div>
				</div>
				<div class="col-md-6 col-sm-6">
						<div class="form-group">
							<input type="text" name="captcha" id="captcha" placeholder=" Captcha Code*">
							<img id="captcha_code" src="captcha_code.php"  style="width: 25%;    float: left;">	
						</div>
					</div>
				
				
				<div class="row">
					<div class="col-md-6">
						
						<input type="submit" value="Submit" class="btn_1" id="submit-contact">
					</div>
				</div>
			</form>
		</div>

and mail-contact.php

<?php session_start(); if($_POST["captcha"]==$_SESSION["captcha_code"]) $client_mail = $_POST['email_contact']; $owner_mail = "pratik@xyz.com"; $msg = ""; $msg .= ""; $msg .= ""; $msg .= ""; $msg .= ""; $msg .= "
Name : ".$_POST['name_contact']." ".$_POST['lastname_contact']."
Email : ".$_POST['email_contact']."
Contact No. : ".$_POST['phone_contact']."
Message : ".$_POST['message_contact']."
"; $subject = "Contact Query for your business"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: $client_mail \r\n"; $subject = "Contact Query for XYZ.com"; //print_r($msg); //die(); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: $client_mail \r\n"; if(mail($owner_mail,$subject,$msg,$headers)){ echo''; echo ''; } else{ echo''; echo ''; } ?>

Can someone help me with correct code.

In mail-contact.php just after the session_start() do a var_dump() on the $_POST array and the $_SESSION array to check that what you expect to see there is what’s there

Thank you for your prompt reply.

I am new to PHP can you please help me with correct code for this page.

Where did you find this code?

Was working on another website and it was working perfectly there.

any issues there as well?

A post was split to a new topic: How to stop a form submitting even when empty

A post was split to a new topic: Empty Form Submitting

I don’t see any code to check whether the user has filled in any of the form fields (other than the CAPTCHA) before you create and send the email.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.