Menu
I have got a contact form with php validation and the code or something is not working and I don’t understand why. I have researched for a suitable answer, but I have had no luck as when the user uses the contact form, then they receive “This page isn’t working” error. I have supplied a screenshot
[code=php]
'[/code]
[code=php]<?php
// error_reporting(E_WARNING);
function readURL($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$secret = " site-keye-here";
$verificationResponse = $_POST["g-recaptcha-response"];
if( empty($verificationResponse) ) die("Google did not POST the required g-recaptha-response");
$response = readURL("https://www.google.com/recaptcha/api/siteverify" . $secret . "&response=" . $verificationResponse . "");
$responseArray = json_decode($response, true);
if( $responseArray["success"] !== true) die("Invalid reCaptcha <a href="javascript:history.go(-1);">Try Again</a>");
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$name = $_POST['name'];
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$dropdown2 = $_POST['dropdown2'];
$dropdown3 = $_POST['dropdown3'];
$subject = $_POST['subject'];
$message = $_POST['message'];
/* If e-mail is not valid show error message */
if (!preg_match("/([w-]+@[w-]+.[w-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Contact Message from www.ncmaphia.co.uk";
$message = "
$name has sent you a message using your contact form:
Name: $name
Email: $email
Crew/Gang: $dropdown
Game: $dropdown2
Reason For Contacting Us: $dropdown3
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location:thank-you.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
[/code]
[code=html]
<div class="col-md-8 contact-grid">
<form action="form-process.php" method="POST">
<input name="name" type="text" value="Name" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}">
<br>
<input name="email" type="text" value="Email" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='email';}">
<br>
<select id="contact" name="dropdown" onchange="handleOption(this)">
<option value="crew/gang">Crew/Gang</option>
<option value="nc maphia">NC Maphia</option>
<option value="deadeye/index">Dead Eye</option>
</select><br>
<select id="contact" name="dropdown2">
<option value="game">Game</option>
<option value="grand theft auto v">Grand Theft Auto V</option>
<option value="red dead redemption ii">Red Dead Redemption II</option>
</select><br>
<select id="contact" name="dropdown3">
<option value="reason for contacting us">Reason for contacting us?</option>
<option value="joining nc maphia">Joining NC Maphia</option>
<option value="recruitment requirments">Recruitment Requirments</option>
<option value="events">Events</option>
<option value="report a member">Report A Member</option>
<option value="webmaster">Webmaster</option>
<option value="general inquiry">General Inquiry</option>
</select><br>
<input name="subject" type="text" value="Subject" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='subject';}">
<br>
<textarea name="message" cols="77" rows="6" value=" " onfocus="this.value='';" onblur="if (this.value == '') {this.value = 'message';}">Message</textarea>
<div class="g-recaptcha" data-sitekey="site-keye-here"></div>
<div class="send">
<input type="submit" value="Send" >
</div>
</form>
</div>
[/code]
<form action="form-process.php" method="POST">
<?php
exit();
}
?>
why this?[code=html]
<form id="test" action="form-process.php" method="POST">
[/code]
<i>
</i> error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
[code=php]
$responseArray = json_decode($response, true);
if( $responseArray["success"] !== true) {
die("<pre>Captcha failed; $response was:n".var_export($response, 1).
"n$responseArray was:n".var_export($responseArray, 1).'</pre>');
}
[/code]
[code=php]
$response = readURL("https://www.google.com/recaptcha/api/siteverify" . $secret . "&response=" . $verificationResponse . "");
[/code]
$verificationResponse
$secret
echo
[code=php]
<?php
// error_reporting(E_WARNING);
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
function readURL($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
echo $secret = "site-key-here";
echo $verificationResponse = $_POST["g-recaptcha-response"];
if( empty($verificationResponse) ) die("Google did not POST the required g-recaptha-response");
$response = readURL("https://www.google.com/recaptcha/api/siteverify/ " . $secret . "&response=" . $verificationResponse . "");
$responseArray = json_decode($response, true);
if( $responseArray["success"] !== true) {
die("<pre>Captcha failed; $response was:n".var_export($response, 1).
"n$responseArray was:n".var_export($responseArray, 1).'</pre>');
}
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$name = $_POST['name'];
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$dropdown2 = $_POST['dropdown2'];
$dropdown3 = $_POST['dropdown3'];
$subject = $_POST['subject'];
$message = $_POST['message'];
/* If e-mail is not valid show error message */
if (!preg_match("/([w-]+@[w-]+.[w-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Contact Message from www.ncmaphia.co.uk";
$message = "
$name has sent you a message using your contact form:
Name: $name
Email: $email
Crew/Gang: $dropdown
Game: $dropdown2
Reason For Contacting Us: $dropdown3
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location:thank-you.html');
exit();
[/code]
[code=html]
<div class="contact">
<div class="container">
<h2>Contact US</h2>
<div class="contact-form">
<div class="col-md-8 contact-grid">
<form id="test" action="form-process.php" method="POST">
<input name="name" type="text" value="Name" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}">
<br>
<input name="email" type="text" value="Email" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='email';}">
<br>
<select id="contact" name="dropdown" onchange="handleOption(this)">
<option value="Crew/Gang">Crew/Gang</option>
<option value="NC Maphia">NC Maphia</option>
<option value="deadeye/index">Dead Eye</option>
</select><br>
<select id="contact" name="dropdown2">
<option value="Game">Game</option>
<option value="Grand Theft Auto V">Grand Theft Auto V</option>
<option value="Red Dead Redemption II">Red Dead Redemption II</option>
</select><br>
<select id="contact" name="dropdown3">
<option value="Platform">Platform</option>
<option value="Xbox One">Xbox One</option>
<option value="PS4">PS4</option>
</select><br>
<select id="contact" name="dropdown4">
<option value="reason for contacting us">Reason for contacting us?</option>
<option value="Joining NC Maphia">Joining NC Maphia</option>
<option value="Recruitment Requirments">Recruitment Requirments</option>
<option value="Events">Events</option>
<option value="Report A Member">Report A Member</option>
<option value="Webmaster">Webmaster</option>
<option value="General Inquiry">General Inquiry</option>
</select><br>
<input name="subject" type="text" value="Subject" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='subject';}">
<br>
<textarea name="message" cols="77" rows="6" value=" " onfocus="this.value='';" onblur="if (this.value == '') {this.value = 'message';}">Message</textarea>
<div class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="6Ler9H8UAAAAAElg86pX58oN-G2a125GwNoBY9X4"></div>
<div class="send">
<input type="submit" disabled value="Send" >
</div>
</form>
</div>
<div class="col-md-4 contact-in">
<div class="address-more">
<h4>Address</h4>
<p>Maze Bank Tower,</p>
<p>Los Santos,</p>
<p>America </p>
</div>
<div class="address-more">
<h4>Chat With Us</h4>
<p>PSN: Kyle-The-Gunman9</p>
<p>PSN: NC_Maphia</p>
<p>Email:<a href="mailto:[email protected]"> info[at]ncmaphia.co.uk</a></p>
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
<script type="text/javascript">
function handleOption(elm) {
if(elm.value == "deadeye/index") { // Check if Dead Eye was selected
console.log("Dead Eye selected, redirecting");
window.location = elm.value + ".html";
}
}
function recaptchaCallback() {
$('submit').removeAttr('disabled');
}
else
alert("Verification Invalid")
};
</script>
[/code]
[code=html]
<input name="name" type="text" value="Name" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}" required="">
[/code]
<i>
</i><form action="/action_page.php">
<label>Name: <input type="text" name="username" required></label>
<input type="submit" value='Send'>
</form>
[code=html]
<div class="contact">
<div class="container">
<h2>Contact US</h2>
<div class="contact-form">
<div class="col-md-8 contact-grid">
<form id="test" action="form-process.php" method="POST">
<label>Name<span> *</span></label>
<input name="name" type="text" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}" required>
<br>
<label>Email<span> *</span></label>
<input name="email" type="text" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='email';}" required>
<br>
<label>Crew/Gang<span> *</span></label>
<select id="contact" name="dropdown" onchange="handleOption(this)" required>
<option value="NC Maphia">NC Maphia</option>
<option value="deadeye/index">Dead Eye</option>
</select><br>
<label>Game<span> *</span></label>
<select id="contact" name="dropdown2" required>
<option value="Grand Theft Auto V">Grand Theft Auto V</option>
<option value="Red Dead Redemption II">Red Dead Redemption II</option>
</select><br>
<label>Platform<span> *</span></label>
<select id="contact" name="dropdown3" required>
<option value="Xbox One">Xbox One</option>
<option value="PS4">PS4</option>
</select><br>
<label>Reason For Contacting Us<span> *</span></label>
<select id="contact" name="dropdown4" required>
<option value="Joining NC Maphia">Joining NC Maphia</option>
<option value="Recruitment Requirments">Recruitment Requirments</option>
<option value="Events">Events</option>
<option value="Report A Member">Report A Member</option>
<option value="Webmaster">Webmaster</option>
<option value="General Inquiry">General Inquiry</option>
</select><br>
<label>Subject</label>
<input name="subject" type="text" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='subject';}">
<br>
<label>Message<span> *</span></label>
<textarea name="message" cols="77" rows="6" value=" " onfocus="this.value='';" onblur="if (this.value == '') {this.value = 'message';}" required>Tell Us in more detail. Why you are contacting us. The more detail you can give us, then the more quicker, we will be able to assist you.</textarea>
<div class="send">
<input type="submit" value="Send" >
<?php
if(!empty($notification)) //This will display notification after submit
{
echo $notification;
}
?>
</div>
</form>
</div>
[/code]
[code=php]
<?php
if($_POST) //If the form is submitted
{
$notification=""; //Used for catching all your messages
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$dropdown = ($_GET['dropdown']) ?$_GET['dropdown'] : $_POST['dropdown'];
$dropdown2 = ($_GET['dropdown2']) ?$_GET['dropdown2'] : $_POST['dropdown2'];
$dropdown3 = ($_GET['dropdown3']) ?$_GET['dropdown3'] : $_POST['dropdown3'];
$dropdown4 = ($_GET['dropdown4']) ?$_GET['dropdown4'] : $_POST['dropdown4'];
$subject = ($_GET['subject']) ?$_GET['subject'] : $_POST['subject'];
$message = ($_GET['message']) ?$_GET['message'] : $_POST['message'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course,
//you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$dropdown) $errors[count($errors)] = 'Please enter which crew/gang you are attempting to contact.';
if (!$dropdown2) $errors[count($errors)] = 'Please enter which game you are referring too.';
if (!$dropdown3) $errors[count($errors)] = 'Please enter which platform you are currently playing on.';
if (!$dropdown4) $errors[count($errors)] = 'We need too know the reason for your message.';
if (!$message) $errors[count($errors)] = 'We need more detail on why you are contacting us.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - change this to your name and email
$to = '[email protected]';
//sender
$from = $email;
//subject and the html message
$subject = 'Hello from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<p>You have recieved a message from $name using your contact form at www.ncmaphia.co.uk
<table>
<tr><td>Name: </td><td>' . $name . '</td></tr>
<tr><td>Email: </td><td>' . $email . '</td></tr>
<tr><td>Crew/Gang: </td><td>' . $dropdown . '</td></tr>
<tr><td>Game: </td><td>' . $dropdown2 . '</td></tr>
<tr><td>Platform: </td><td>' . $dropdown3 . '</td></tr>
<tr><td>Reason For Contacting Us: </td><td>' . $dropdown4 . '</td></tr>
<tr><td>Subject: </td><td>' . $subject . '</td></tr>
<tr><td>Message: </td><td>' . $message . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else $notification.= 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
$notification.= $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
$notification.= '<a href="contact.html">Back</a>';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";
$headers .= 'From: ' . $from . "rn";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
} //First If loop
?>
[/code]
<input name="name" type="text" value="Name"
onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}" required="">
<input name="personname" type="text" value="" placeholder="Name" required>
[code=html]
<div class="contact">
<div class="container">
<h2>Contact US</h2>
<div class="contact-form">
<div class="col-md-8 contact-grid">
<form id="test" action="form-process.php" method="POST">
<input name="personname" type="text" placeholder="Name" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}" required>
<br>
<input name="email" type="text" placeholder="Email" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='email';}" required>
<br>
<select id="contact" name="dropdown" placeholder="Crew/Gang" onchange="handleOption(this)" required>
<option value="NC Maphia">NC Maphia</option>
<option value="deadeye/index">Dead Eye</option>
</select><br>
<select id="contact" name="dropdown2" placeholder="Game" required>
<option value="Grand Theft Auto V">Grand Theft Auto V</option>
<option value="Red Dead Redemption II">Red Dead Redemption II</option>
</select><br>
<select id="contact" name="dropdown3" Placeholder="Platform" required>
<option value="Xbox One">Xbox One</option>
<option value="PS4">PS4</option>
</select><br>
<select id="contact" name="dropdown4" placeholder="Reason For Contacting Us" required>
<option value="Joining NC Maphia">Joining NC Maphia</option>
<option value="Recruitment Requirments">Recruitment Requirments</option>
<option value="Events">Events</option>
<option value="Report A Member">Report A Member</option>
<option value="Webmaster">Webmaster</option>
<option value="General Inquiry">General Inquiry</option>
</select><br>
<input name="subject" type="text" placeholder="Subject" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='subject';}">
<br>
<textarea name="message" cols="77" rows="6" placeholder="Message" onfocus="this.value='';" onblur="if (this.value == '') {this.value = 'message';}" required></textarea>
<div class="send">
<input type="submit" value="Send" >
<?php
if(!empty($notification)) //This will display notification after submit
{
echo $notification;
}
?>
</div>
</form>
</div>
[/code]
[code=php]
<?php
if($_POST) //If the form is submitted
{
$notification=""; //Used for catching all your messages
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$personname = ($_GET['personname']) ? $_GET['personname'] : $_POST['personname'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$dropdown = ($_GET['dropdown']) ?$_GET['dropdown'] : $_POST['dropdown'];
$dropdown2 = ($_GET['dropdown2']) ?$_GET['dropdown2'] : $_POST['dropdown2'];
$dropdown3 = ($_GET['dropdown3']) ?$_GET['dropdown3'] : $_POST['dropdown3'];
$dropdown4 = ($_GET['dropdown4']) ?$_GET['dropdown4'] : $_POST['dropdown4'];
$subject = ($_GET['subject']) ?$_GET['subject'] : $_POST['subject'];
$message = ($_GET['message']) ?$_GET['message'] : $_POST['message'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course,
//you should validate the email
if (!$personname) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$dropdown) $errors[count($errors)] = 'Please enter which crew/gang you are attempting to contact.';
if (!$dropdown2) $errors[count($errors)] = 'Please enter which game you are referring too.';
if (!$dropdown3) $errors[count($errors)] = 'Please enter which platform you are currently playing on.';
if (!$dropdown4) $errors[count($errors)] = 'We need too know the reason for your message.';
if (!$message) $errors[count($errors)] = 'We need more detail on why you are contacting us.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - change this to your name and email
$to = '[email protected]';
//sender
$from = $email;
//subject and the html message
$subject = 'Hello from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<p>You have recieved a message from $name using your contact form at www.ncmaphia.co.uk
<table>
<tr><td>Name: </td><td>' . $name . '</td></tr>
<tr><td>Email: </td><td>' . $email . '</td></tr>
<tr><td>Crew/Gang: </td><td>' . $dropdown . '</td></tr>
<tr><td>Game: </td><td>' . $dropdown2 . '</td></tr>
<tr><td>Platform: </td><td>' . $dropdown3 . '</td></tr>
<tr><td>Reason For Contacting Us: </td><td>' . $dropdown4 . '</td></tr>
<tr><td>Subject: </td><td>' . $subject . '</td></tr>
<tr><td>Message: </td><td>' . $message . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else $notification.= 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
$notification.= $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
$notification.= '<a href="contact.html">Back</a>';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";
$headers .= 'From: ' . $from . "rn";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
} //First If loop
?>
[/code]
[code=php]if($_POST) //If the form is submitted[/code]
with this [code=php]if(isset)($_POST["submit"])) //If the form is submitted[/code]
and now i am receiving the following:if(isset)($_POST["submit"])) //If the form is submitted
if( isset( $_POST["submit"]) ) //If the form is submitted
[code=html]
<div class="contact">
<div class="container">
<h2>Contact US</h2>
<div class="contact-form">
<div class="col-md-8 contact-grid">
<form id="test" action="form-process.php" method="POST">
<input name="name" type="text" placeholder="Name" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}" required>
<br>
<input name="email" type="text" placeholder="Email" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='email';}" required>
<br>
<select id="contact" name="dropdown" onchange="handleOption(this)" required>
<option value="" disabled selected>Crew/Gang</option>
<option value="NC Maphia">NC Maphia</option>
<option value="deadeye/index">Dead Eye</option>
</select><br>
<select id="contact" name="dropdown2" required>
<option value="" disabled selected>Game</option>
<option value="Grand Theft Auto V">Grand Theft Auto V</option>
<option value="Red Dead Redemption II">Red Dead Redemption II</option>
</select><br>
<select id="contact" name="dropdown3" required>
<option value="" disabled selected>Platform</option>
<option value="Xbox One">Xbox One</option>
<option value="PS4">PS4</option>
</select><br>
<select id="contact" name="dropdown4" required>
<option value="" disabled selected>Reason For Contacting Us</option>
<option value="Joining NC Maphia">Joining NC Maphia</option>
<option value="Recruitment Requirments">Recruitment Requirments</option>
<option value="Events">Events</option>
<option value="Report A Member">Report A Member</option>
<option value="Webmaster">Webmaster</option>
<option value="General Inquiry">General Inquiry</option>
</select><br>
<input name="subject" type="text" placeholder="Subject" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='subject';}">
<br>
<textarea name="message" cols="77" rows="6" placeholder="Message" onfocus="this.value='';" onblur="if (this.value == '') {this.value = 'message';}" required></textarea>
<div class="g-recaptcha" data-sitekey="6Ler9H8UAAAAAElg86pX58oN-G2a125GwNoBY9X4"></div>
<div class="send">
<input type="submit" name="submit" value="Send" >
</div>
</form>
</div>
[/code]
[code=php]
<!--A Design by Kyle Logan
Author: Kyle Logan
Author URL: http://www.kylejamelogan.co.uk
License: Creative Commons Attribution 3.0 Unported
License URL: http://www.kylejameslogan.co.uk
-->
<!--
************************************************************
* Copyright Policy *
************************************************************
* Copyright © 2017 Kyle Logan. All Rights Reserved *
************************************************************
* This is the copyright policy for the two parties *
* involved and they include the license holder and *
* the client. All of the documents and everything that *
* is joint to this website must not be copyrighted *
* under the copyright laws of the U.K and U.S.A as it *
* can result in criminal proceedings being held against *
* you. If you also get this code then you must not *
* remove the developed by Kyle Logan within the footer *
* if this does occur then you will frace criminal *
* proceedings and/or the website may be destroyed. *
************************************************************
-->
<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
if(isset($_POST["submit"])) //If the form is submitted
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
//your site secret key
$secret = 'My-Key-Here';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success):
{
$notification=""; //Used for catching all your messages
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$errors = [];
$name = $_POST['name'];
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$dropdown2 = $_POST['dropdown2'];
$dropdown3 = $_POST['dropdown3'];
$dropdown4 = $_POST['dropdown4'];
$subject = $_POST['subject'];
$message = $_POST['message'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course,
//you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$dropdown) $errors[count($errors)] = 'Please enter which crew/gang you are attempting to contact.';
if (!$dropdown2) $errors[count($errors)] = 'Please enter which game you are referring too.';
if (!$dropdown3) $errors[count($errors)] = 'Please enter which platform you are currentlyplaying on.';
if (!$dropdown4) $errors[count($errors)] = 'We need too know the reason for your message.';
if (!$message) $errors[count($errors)] = 'We need more detail on why you are contacting us.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - change this to your name and email
$to = '[email protected]';
//sender
$from = $email;
//subject and the html message
$subject = 'Hello from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<p>You have recieved a message from $name using your contact form at www.example.co.uk
<table>
<tr><td>Name: </td><td>' . $name . '</td></tr>
<tr><td>Email: </td><td>' . $email . '</td></tr>
<tr><td>Crew/Gang: </td><td>' . $dropdown . '</td></tr>
<tr><td>Game: </td><td>' . $dropdown2 . '</td></tr>
<tr><td>Platform: </td><td>' . $dropdown3 . '</td></tr>
<tr><td>Reason For Contacting Us: </td><td>' . $dropdown4 . '</td></tr>
<tr><td>Subject: </td><td>' . $subject . '</td></tr>
<tr><td>Message: </td><td>' . $message . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = mail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) header('location: thank-you.html', true, 303);
else:
$errMsg = 'Robot verification failed, please try again.';
endif;
else:
$errMsg = 'Please click on the reCAPTCHA box.';
endif;
else:
$errMsg = '';
$succMsg = '';
endif;
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
$notification.= $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
$notification.= '<a href="contact.html">Back</a>';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";
$headers .= 'From: ' . $from . "rn";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
} //First If loop
?>
[/code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html>
<html>
$name = $_POST['name'];
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$dropdown2 = $_POST['dropdown2'];
$dropdown3 = $_POST['dropdown3'];
$dropdown4 = $_POST['dropdown4'];
$subject = $_POST['subject'];
$message = $_POST['message'];
no filtering with filter_var to validate the input.$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?
secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
0.1.9 — BETA 4.26