Browse Source

Updated contact form to use centeralized alert.jrtechs.net service

master
jrtechs 2 years ago
parent
commit
b73831188e
3 changed files with 5 additions and 97 deletions
  1. +1
    -21
      README.md
  2. +0
    -73
      contactform.php
  3. +4
    -3
      index.html

+ 1
- 21
README.md View File

@ -3,24 +3,4 @@ Simple bootstrap site for my personal portfolio website.
![Screenshot](./screenshot.png) ![Screenshot](./screenshot.png)
Check it out live [here](https://jrtechs.me)
## Installation notes
If you wish to run a live instance of this site,
you need apache installed and php configured to
send email.
To install dependency for sending mail on a ubuntu server:
```
sudo apt-get install sendmail
```
On the contact form I use google's
[reCAPTCHA](https://developers.google.com/recaptcha/) api. If you wish
to use reCAPTCHA on your website, you need to sign up for an account on google's website.
The secret for the captcha goes in a text file above the root
directory for this website called "captchaSecret.txt". The destination
email address is stored above the root directory in a file called "email.txt".
https://www.google.com/recaptcha/admin
Check it out live [here](https://jrtechs.me)

+ 0
- 73
contactform.php View File

@ -1,73 +0,0 @@
<?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
*/
$secret_file_path = '../captchaSecret.txt';
$personal_email_path = '../email.txt';
if(isset($_POST['submit']))
{
if(isset($_POST['g-recaptcha-response']))
{
$secret = file_get_contents($secret_file_path, FILE_USE_INCLUDE_PATH);
$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' => $secret,
'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/messageSent.html');
}
}
}
}

+ 4
- 3
index.html View File

@ -336,16 +336,16 @@
<div class="row"> <div class="row">
<div class="contact-section w-100"> <div class="contact-section w-100">
<div class="container"> <div class="container">
<form action="contactform.php" method="post">
<form action="https://alert.jrtechs.net/contact" method="post">
<div class="row"> <div class="row">
<div class="col-md-6 form-line"> <div class="col-md-6 form-line">
<div class="form-group"> <div class="form-group">
<label>Your name</label> <label>Your name</label>
<input type="text" class="form-control" id="" placeholder=" Enter Name" name="name">
<input type="text" class="form-control" id="" placeholder="Enter Name" name="name">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="exampleInputEmail">Email Address</label> <label for="exampleInputEmail">Email Address</label>
<input type="email" class="form-control" id="exampleInputEmail" placeholder=" Enter Email Address" name="email">
<input type="email" class="form-control" id="exampleInputEmail" placeholder="Enter Email Address" name="email">
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
@ -354,6 +354,7 @@
<textarea class="form-control" id="description" placeholder="Enter Your Message" name="message"></textarea> <textarea class="form-control" id="description" placeholder="Enter Your Message" name="message"></textarea>
</div> </div>
<div> <div>
<input type="hidden" id="site" name="site" value="jrtechs.me">
<div class="g-recaptcha" data-sitekey="6LceWF8UAAAAAIsd7F6iY_Pywt4fJsJlFNPtEgi9"></div> <div class="g-recaptcha" data-sitekey="6LceWF8UAAAAAIsd7F6iY_Pywt4fJsJlFNPtEgi9"></div>
</div> </div>
</div> </div>

Loading…
Cancel
Save