Browse Source

Added contact form to portfolio website

master
jrtechs 6 years ago
parent
commit
051dad2419
2 changed files with 105 additions and 3 deletions
  1. +72
    -0
      contactform.php
  2. +33
    -3
      index.html

+ 72
- 0
contactform.php View File

@ -0,0 +1,72 @@
<?php
/**
* This file validates input sent from a contact form in {@link index.html}.
* After verifying that the captcha is correct, it sends the email
* to my personal address.
*
* @author Jeffery Russell 6-17-18
*/
if(isset($_POST['submit']))
{
if(isset($_POST['g-recaptcha-response']))
{
$secret_file_path = '../captchaSecret.txt';
$secret = file_get_contents($secret_file_path, FILE_USE_INCLUDE_PATH);
$personal_email_path = '../email.txt';
$toEmail = file_get_contents($personal_email_path, FILE_USE_INCLUDE_PATH);
if($secret === false)
{
echo "File with the captcha secret is not set:";
echo $secret_file_path;
}
else if($toEmail === false)
{
echo "File with personal email address is not set:";
echo $personal_email_path;
}
else
{
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => '6LceWF8UAAAAAGueUiQyI-W_saWPInFfLW6nM8pv',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false)
{
echo "<p>You are a bot! Go away!</p>";
}
else if ($captcha_success->success==true)
{
$fromName = stripslashes($_POST["name"]);
$fromEmail = stripslashes($_POST["email"]);
$subject = "Jrtechs.me Form Submission - " . $fromEmail;
$emailMessage = stripslashes($_POST["message"]);
$message = "Message from contact form on jrtechs.me\nName:
$fromName \nEmail:\n$fromEmail \nMessage:\n$emailMessage";
$headers = "From: $fromEmail";
$response = $_POST[g-recaptcha-response];
mail($toEmail, $subject, $message, $headers);
header('Location:https://jrtechs.me/index.html');
}
}
}
}

+ 33
- 3
index.html View File

@ -249,9 +249,36 @@
<h2 class="text-center">Contact Me</h2> <h2 class="text-center">Contact Me</h2>
<hr class="star-primary"> <hr class="star-primary">
<div class="row"> <div class="row">
<div class="col-lg-8 mx-auto">
<center><p>Jeffery@jrtechs.net</p></center>
</div>
<!--<center><p>Jeffery@jrtechs.net</p></center>-->
<div class="contact-section w-100">
<div class="container">
<form action="contactform.php" method="post">
<div class="row">
<div class="col-md-6 form-line">
<div class="form-group">
<label>Your name</label>
<input type="text" class="form-control" id="" placeholder=" Enter Name" name="name">
</div>
<div class="form-group">
<label for="exampleInputEmail">Email Address</label>
<input type="email" class="form-control" id="exampleInputEmail" placeholder=" Enter Email id" name="email">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for ="description"> Message</label>
<textarea class="form-control" id="description" placeholder="Enter Your Message" name="message"></textarea>
</div>
<div>
<div class="g-recaptcha" data-sitekey="6LceWF8UAAAAAIsd7F6iY_Pywt4fJsJlFNPtEgi9"></div>
<!--<button type="submit" name="submit" class="btn btn-default submit"><i class="fa fa-paper-plane" aria-hidden="true"></i>Send Message</button>-->
<input type="submit" id="submit" name="submit" value="Submit">
</div>
</div>
</div>
</form>
</div>
</div>
</div> </div>
</div> </div>
</section> </section>
@ -861,6 +888,9 @@
<!-- Plugin JavaScript --> <!-- Plugin JavaScript -->
<script src="js/jquery.easing.min.js"></script> <script src="js/jquery.easing.min.js"></script>
<!-- For contact form -->
<script src='https://www.google.com/recaptcha/api.js'></script>
<!-- <!--
__,,,,_ __,,,,_

Loading…
Cancel
Save