diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 64 |
1 files changed, 49 insertions, 15 deletions
@@ -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> |