-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
47 lines (42 loc) · 1.96 KB
/
contact.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require_once 'inc/mailer.php';
/** setup mailer and captcha services */
$mailer = new mailer();
$recaptchService = new Zend_Service_ReCaptcha($mailer->recaptchPublicKey, $mailer->recaptchPrivateKey);
$postSubmit = filter_input(INPUT_POST, 'submit', FILTER_DEFAULT);
$postRecaptchResponse = filter_input(INPUT_POST, 'g-recaptcha-response', FILTER_DEFAULT);
/** contact form was submitted, try to send the email */
if (isset($postSubmit)) {
if($recaptchService->verify($postRecaptchResponse)->isValid()) {
$mailer->setFromName(filter_input(INPUT_POST, 'name', FILTER_DEFAULT));
$mailer->setReplyTo(filter_input(INPUT_POST, 'email', FILTER_DEFAULT));
$mailer->setSubject(filter_input(INPUT_POST, 'submit', FILTER_DEFAULT));
$mailer->setBody(filter_input(INPUT_POST, 'message', FILTER_DEFAULT));
$sendStatus = $mailer->send();
} else {
logger::addError('Please try re-entering the Recaptch.');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Contact Form Example</title>
</head>
<body>
<?php if (logger::hasMessages()) { ?>
<div class="<?php (logger::hasErrors()) ? 'error' : 'success'; ?>">
<div><?php echo (logger::hasErrors()) ? implode('<br>', logger::getErrors()) : implode('<br>', logger::getSuccess()); ?></div>
</div>
<?php } ?>
<form target="" method="post" action="" name="contact">
<input type="text" placeholder="Your Name" name="name" id="email"><br>
<input type="text" placeholder="Your Email Address" name="email" id="email"><br>
<input type="text" placeholder="Summary of your question" name="subject" id="subject"><br>
<textarea rows="8" name="message" id="message"></textarea><br>
<?php echo $recaptchService->getHTML(); ?><br>
<button type="submit" name="submit" value="submit">Send</button><br>
</form>
</body>
</html>