Finally usable form, mail link in footer
This commit is contained in:
45
contact.php
45
contact.php
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$ok = true;
|
||||
$grecaptcha_secret_key = '6LcGPU8UAAAAANB2tVqhxbvUSkbxJlOjxLDa8UT4';
|
||||
if ($_POST['email'] && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$email = $_POST['email'];
|
||||
} else {
|
||||
@@ -19,11 +20,47 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$ok = false;
|
||||
echo "<p>Message validation failed</p>";
|
||||
}
|
||||
if ($ok) {
|
||||
// TODO: Sendmail
|
||||
echo "<p>Validation passed</p>";
|
||||
if ($_POST['g-recaptcha-response']) {
|
||||
$url = 'https://www.google.com/recaptcha/api/siteverify';
|
||||
$params = array(
|
||||
'secret' => $grecaptcha_secret_key,
|
||||
'response' => $_POST['g-recaptcha-response'],
|
||||
);
|
||||
$result = file_get_contents($url, false, stream_context_create(array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => http_build_query($params)
|
||||
)
|
||||
)));
|
||||
if (!json_decode($result, true)['success']) {
|
||||
$ok = false;
|
||||
echo "<p>recaptcha remote validation failed</p>";
|
||||
}
|
||||
} else {
|
||||
echo "<p>Validation failed. Please check your data</p>";
|
||||
$ok = false;
|
||||
echo "<p>recaptcha validation failed</p>";
|
||||
}
|
||||
if ($ok) {
|
||||
$ip = $_SERVER["REMOTE_ADDR"];
|
||||
$message = "Message from $name <$email>, ip: $ip\r\n $body";
|
||||
$answer = (int)$_POST["answ"];
|
||||
$headers = 'From: Contact Form <noreply@teamfnd.ru>' . "\r\n" .
|
||||
'Reply-To: No Reply <noreply@teamfnd.ru>' . "\r\n" .
|
||||
'Content-Type: text/plain; charset=UTF-8; format=flowed' . "\r\n" .
|
||||
'X-Mailer: PHP/' . phpversion();
|
||||
mail('info@teamfnd.ru', "Contact Form on teamfnd.ru from $name <$email>", $message, $headers);
|
||||
?>
|
||||
<div style="text-align: center; margin-top: 70px;">
|
||||
<h1 style="color: green;">Success!</h1>
|
||||
<p>Your message has been sent.</p>
|
||||
<p>We will reply you as soon as it is possilble.</p>
|
||||
<p>You will be redirected back on site soon.</p>
|
||||
</div>
|
||||
<?php
|
||||
echo '<meta http-equiv="refresh" content="4;URL='.$_SERVER['HTTP_REFERER'].'" />';
|
||||
} else {
|
||||
echo '<h1 style="color: red;">Validation failed. Please check your data</h1>';
|
||||
}
|
||||
} else {
|
||||
echo 'Method not allowed';
|
||||
|
||||
Reference in New Issue
Block a user