Having a problem with ReCaptcha. Even if checkbox is checked, it still returns false. I have triple checked my keys and happy they are correct. I am using code based on that successfully used on another of my sites. Cannot see what is wrong.
For ease of reference, I have copied all the relevant coding. Hopefully someone will see straight away what I've done wrong.
Form Code:
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" placeholder="Please enter your first name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" placeholder="Please enter your surname" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="email" name="email" placeholder="Please enter your email address" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="tel" name="telephone" placeholder="Please enter your phone number" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><div class="g-recaptcha" data-sitekey="6LejdlwUAAAAAHb5qaNIhfDzxL1i9a9sCyw8dLzD"></div></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> <br> Email Form
</td>
</tr>
</table>
</form>
Code from the PHP:
<?php
// Code from ReCaptcha evaluation:
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "************************************";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are a spammer ! Your form has been rejected.</h2>';
} else
// End Code from ReCaptcha evaluation.
Many Thanks
Tim
Related
This site is hosted on shared hosting, unfortunately, the only thing the host seems to make available is the access log, not the PHP error log, so I'm having trouble figuring out the specific error here.
I'm trying to do a very minimal, simple contact form in PHP, without much validation or complexity. Getting a 500 error, though I'm sure I'm overlooking something basic.
Any assistance greatly appreciated.
HTML:
<form name="htmlform" method="post" action="collins_contact.php">
<table width="450px" cellpadding="20px">
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="first_name">First Name</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="last_name">Last Name</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="email">Email Address</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="telephone">Telephone</label>
</td>
<td valign="top">
<input type="text" name="phone" maxlength="30" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="comments">Questions / Comments</label>
</td>
<td valign="top">
<textarea name="message" maxlength="1000" cols="25" rows="6"></textarea>
</td>
<tr><td> </td></tr>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
<tr><td> </td></tr>
</table>
</form>
PHP
<?php
if (isset($_POST["first_name"]) && isset($_POST["email"]) && isset($_POST["message"])) {
$name = $_POST["first_name"];
$email = $_POST["email"];
$subject = "Contact Form Submission";
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = "contact#domain.com";
if (mail($to, $subject, $message, $header)) {
header("Location: index.html");
} else {
echo("Error With Form Submission");
}
}
?>
Permissions needed to be changed to 0644 on the php file, then it worked.
I have a client with a website made in php who is newly hosted with us. I have no idea why, but after transferring his website on our servers, the Contact us form's php code is visible to the public. I have no idea why that is, and would appreciate to be directed towards a solution.
(Sorry about the ugly display)
example of what is happening on the live website
<?php
if ($error) error_message($error);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="post" action="index.php?go=sendcontact#chkerr">
<tr valign="top">
<td class="formfield1" width="30%">Name</td>
<td style="padding-bottom: 5px;" width="70%"><input name="name" type="text" size="25" maxlength="50" value="<? echo $_POST["name"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">Phone number</td>
<td style="padding-bottom: 5px;"><input name="phone" type="text" size="25" maxlength="50" value="<? echo $_POST["phone"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">Email address</td>
<td style="padding-bottom: 5px;"><input name="email" type="text" size="25" maxlength="100" value="<? echo $_POST["email"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">How do you prefer to be contacted?</td>
<td style="padding-bottom: 5px;"><input name="contactpref" type="radio" value="Phone"<? if ($POSTED["contactpref"] == "Phone") echo " checked"; ?>> Phone <input name="contactpref" type="radio" value="Email"<? if ($POSTED["contactpref"] == "Email") echo " checked"; ?>> Email</td>
</tr>
<tr valign="top">
<td class="formfield1">How did you find out about Bella Vista?</td>
<td style="padding-bottom: 5px;"><input name="heardfrom" type="text" size="25" maxlength="50" value="<? echo $_POST["heardfrom"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">Please tell us what you're looking for, or if you have any questions.</td>
<td style="padding-bottom: 5px;"><textarea name="question" cols="40" rows="8"><? echo $_POST["question"] ?></textarea></td>
</tr>
<!--
<tr valign="top">
<td class="formfield1"> </td>
<td style="padding-bottom: 5px;">
<div>Please enter the code in the text field below</div>
<div><img src="captcha.php" width="230" height="45" alt="Captcha code" /></div>
<div><input type="text" name="frm_cap" size="25" value="" /></div>
</td>
</tr>
-->
<tr valign="top">
<td class="formfield1"><!-- Verification --></td>
<td style="padding-bottom: 5px;"><input type="submit" name="Submit" value="Send"></td>
</tr>
</form>
</table>
<?php
You have to replace all the short PHP opening tags <?with the long version : <?php
Or you can take a look at this : How to enable PHP short tags?
This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I have created a form and would like the information to be sent to my email using php. The information submits, and I receive an e-mail, but the email only displays the first and last name of input by the individual submitting the form. I would like to know what is missing from either the php side or html side.
Thank You
<form name="contactform" method="post" action="appraisal_form.php">
<table width="500px">
<tr>
<td>
<label for="first_name">First Name *</label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name *</label>
</td>
<td>
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="email">Email Address *</label>
</td>
<td>
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="telephone">Telephone Number</label>
</td>
<td>
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<!--- Property Type-->
<tr>
<td>
<label for="lender">Lender *</label>
</td>
<td>
<input type="text" name="lender" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_officer">Loan Officer *</label>
</td>
<td>
<input type="text" name="loan_officer" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="property_address">Email Address *</label>
</td>
<td>
<input type="text" name="property_address" maxlength="100" size="30">
</td>
</tr>
<tr>
<td>
<label for="city">City *</label>
</td>
<td>
<input type="text" name="city" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="zip">Zip Code *</label>
</td>
<td>
<input type="text" name="zip" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="pin">PIN(Permenant Index Number) *</label>
</td>
<td>
<input type="text" name="pin" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="rooms">Number of Rooms *</label>
</td>
<td>
<input type="text" name="rooms" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="bath">Number of Bathrooms *</label>
</td>
<td>
<input type="text" name="bath" maxlength="80" size="30">
</td>
</tr>
<!--- Garage /yes or no-->
<tr>
<td>
<label for="plat">Plat of Survey *</label>
</td>
<td>
<input type="text" name="plat" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="borrow">Borrowers Name *</label>
</td>
<td>
<input type="text" name="borrow" maxlength="80" size="30">
</td>
</tr>
<!--- sale /refinance-->
<tr>
<td>
<label for="price">Purchase Price *</label>
</td>
<td>
<input type="text" name="price" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_amount">Loan Amount *</label>
</td>
<td>
<input type="text" name="loan" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="cod">C.O.D *</label>
</td>
<td>
<input type="text" name="cod" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="invoice">Invoice *</label>
</td>
<td>
<input type="text" name="invoice" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="comments">Comments *</label>
</td>
<td>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="submit" id="submit" value="Submit">
<input type="reset" name="Reset" id="reset" value="reset">
</td>
</tr>
</table>
</form>
PHP
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$lender = $_POST['lender']; // required
$loan_officer = $_POST['loan_officer']; // required
$property_address = $_POST['property_address']; // required
$city = $_POST['city']; // required
$zip = $_POST['zip']; // not required
$pin = $_POST['pin']; // required
$rooms = $_POST['rooms']; // required
$bath = $_POST['bath']; // required
$plat = $_POST['plat']; // required
$borrow = $_POST['borrow']; // not required
$price = $_POST['price']; // required
$cod = $_POST['cod']; // not required
$comments = $_POST['comments']; // required
$to = "rosaliam2#yahoo.com";
$subject = "New Appraisal Request";
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid. <br />';
}
mail($to, $subject, $message, "From" . $first_name . $last_name);
echo "Your Information has been sent";
?>
Actually there is no message variable to send!!
you are just sending $first_name and $last_name as headers!
I have my login table in mysql is like this
id
fname
lname
email
contactno
userid
password
acctype
status
Now my form is like this
<form name="frm" method="post" action="registerform.php">
<table id="new-account" class="create-an-account" width="100%" border="1" cellspacing="10px" cellpadding="10px">
<tr>
<td width="45%">
<label for="firstname">First Name</label>
<input type="text" style="width:230px;" name="Firstname" id="Firstname" /></td>
<td width="10%"></td>
<td width="45%">
<label for="lastname">Last Name:</label>
<input type="text" style="width:230px;" name="LastName" id="LastName" />
</td>
</tr>
<tr>
<td>
<label for="">Account Type</label>
<select class="select" name="at" id="ValidSelection" style="width:245px;" >
<option value="0">Select Account Type</option>
<option value="agent">agent</option>
<option value="admin">admin</option>
</select>
</td>
</tr>
<tr>
<td><label for="">Email Id:</label></td>
</tr>
<tr>
<td><input type="text" name="email" id="ValidEmail" style="width:230px;"/></td>
</tr>
<tr>
<td><label for="">Contact Number</label></td>
</tr>
<tr>
<td><input type="text" name="contact" id="ValidNumber" style="width:230px" /></td>
</tr>
<tr>
<td><label for=""><strong>Choose Your Login Id:</strong></label>
<input type="text" style="width:230px;" name="LoginId" id="LoginId"/>
</td>
</tr>
<tr>
<td><label for=""><strong>Password: <br /></strong></label></td>
</tr>
<tr>
<td><input type="password" style="width:230px;" name="Password" id="ValidPassword" /></td>
</tr>
<tr>
<td><label for="">Confirm Password:</label></td>
</tr>
<tr>
<td>
<input type="password" style="width:230px;" name="ConfirmPassword" id="ValidConfirmPassword"
/>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="signup" value="Create Account" style="margin-top:20px" /></td>
</tr>
</table>
and for insert data my php code is like this
<?php
if(isset($_REQUEST['signup'])) {
mysql_query("insert into login (`fname`,`lname`,`email`,`contactno`,`userid`,`password`,`acctype`,`status`) values('".$_REQUEST['Firstname']."','".$_REQUEST['LastName']."','".$_REQUEST['email']."','".$_REQUEST['contact']."','".$_REQUEST['LoginId']."','".$pswd."','".$_REQUEST['at']."','active')");
}
?>
Now here when I am reloading the page it is automatically inserting the last entered values to the database. So here can someone kindly tell me what is the issue here? Any help and suggestions are welcome.
If you reload the page after submitting a form, it will keep the POST data. To solve this follow the below things :
You can redirect to some other page after inserting the data, use header("location:new_page.php")
You can unset REQUEST, use unset($_REQUEST) after insert
after inserting the $_POST data use redirect to avoid this situation .
even you can redirect to same page like this :-
header('Location: '.$_SERVER['PHP_SELF']);
exit;
I have recently created a contact form with PHP mailer which is finally working. However the success message is breaking my page and displaying in the top left corner instead of underneath the form. As you can see below.
This is the HTML:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
</table>
<input type="submit" value="Submit" name="submit">
<?php
if ($success) {
echo $success;
}
?>
</form>
It also creates a huge blank white area in the middle of my page under the form. Does anyone know why this is? or how I would go about debugging it?
You should put this in a div or a span
<div style="text-align:center;"> <?php
if ($success) {
echo $success;
}
?>
</div>
Try following code:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
<?php
if ($success) {?>
<tr><td colspan="2">
<?php echo $success; ?>
</td></tr>
<?php }
?>
</table>
<input type="submit" value="Submit" name="submit">
</form>