summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2021-07-01 16:41:10 -0400
committerAdam T. Carpenter <atc@53hor.net>2021-07-01 16:41:10 -0400
commit3018a9c8d8f16740602540d97e3b0b5db002f9e6 (patch)
tree987d58d5125e08bec015ab8152c64d15e77bf6b7 /index.php
parent11c7f36ffcbaff3e0f2960903afade750f0c9c9d (diff)
downloadcarpentertutoring-3018a9c8d8f16740602540d97e3b0b5db002f9e6.tar.xz
carpentertutoring-3018a9c8d8f16740602540d97e3b0b5db002f9e6.zip
finished mailing form, updated policies
Diffstat (limited to 'index.php')
-rw-r--r--index.php64
1 files changed, 49 insertions, 15 deletions
diff --git a/index.php b/index.php
index 094f670..a726a08 100644
--- a/index.php
+++ b/index.php
@@ -356,23 +356,9 @@
<!-- contact box -->
<section id="contact">
- <?php
- // handle form submission
- if (isset($_POST['name'], $_POST['email'], $_POST['body'])) {
- $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
-
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- echo 'Bad email';
- }
-
- mail('atc@53hor.net', 'test', 'test');
- echo $email;
- echo 'Thank you for your email!';
- }
- ?>
-
<form class="card" action="/#contact" method="post">
<h2>Contact</h2>
+
<label for="name">Name</label>
<input name="name" type="text" id="name" placeholder="Jane Doe" required />
@@ -383,6 +369,54 @@
<textarea name="body" id="body" placeholder="Briefly describe your inquiry, including any services or areas of study you're interested in." required></textarea>
<button type="submit" class="button"><img src="/assets/icons/send-circle.svg" alt="send" />Send</button>
+
+ <?php
+
+ use PHPMailer\PHPMailer\PHPMailer;
+
+ require('PHPMailer-master/src/PHPMailer.php');
+ require('PHPMailer-master/src/SMTP.php');
+ require('PHPMailer-master/src/Exception.php');
+
+ // handle form submission
+ if (isset($_POST['name'], $_POST['email'], $_POST['body'])) {
+ $body = substr(strip_tags($_POST['body']), 0, 16384);
+ $name = substr(strip_tags($_POST['name']), 0, 255);
+
+ if (!PHPMailer::validateAddress($_POST['email'])) {
+ echo 'Bad email';
+ }
+
+ $email = $_POST['email'];
+
+ $smtpuser = file_get_contents('/var/carpentertutoring/smtpuser');
+ $smtppass = file_get_contents('/var/carpentertutoring/smtppass');
+ $address = file_get_contents('/var/carpentertutoring/address');
+
+ $mail = new PHPMailer();
+ $mail->isSMTP();
+ $mail->Host = 'smtp.gmail.com';
+ $mail->Port = 465;
+ $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
+ $mail->SMTPAuth = true;
+ $mail->Username = $smtpuser;
+ $mail->Password = $smtppass;
+ $mail->setFrom($smtpuser, $name);
+ $mail->addReplyTo($email, $name);
+ $mail->addAddress($address);
+ $mail->Subject = 'Tutoring Inquiry';
+ $mail->Body = $body;
+
+ if (!$mail->send()) {
+ echo 'There was a problem sending your message. Please try again later or <a href="tel:1-757-335-7555">call (757) 335-7555</a>.';
+ echo '<!--Send error: ' . $mail->ErrorInfo . '-->';
+ } else {
+ echo "Your message was successfully sent.";
+ }
+ } else {
+ echo "Send us a message and we'll reply by mail as soon as possible. Please note that your email address will not be stored on our server. It will only be used to contact you with a reply.";
+ }
+ ?>
</form>
</section>