-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact-page.php
130 lines (130 loc) · 6.13 KB
/
contact-page.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
* Template Name: Contact Page
* Description: Page template with a Contact Us form below the text
*/
$my_email = "";
$my_text = "";
$my_email_error = false;
$my_captcha_error = false;
$my_success = false;
$secret = get_theme_mod('recaptcha_secret');
$ip = null;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
if (isset($_POST['myEmail'])): $my_email = trim($_POST['myEmail']); endif;
if (isset($_POST['myText'])): $my_text = trim($_POST['myText']); endif;
if (isset($_POST['g-recaptcha-response'])) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array('secret' => $secret,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $ip);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === false || !boolval(json_decode($result, true)['success'])) {
$my_captcha_error = "Error! Failed to identify you as a human.";
} else {
if ($my_email != "" && $my_text != "") {
$subject = 'New Message From ' . esc_html($my_email);
if (!wp_mail(get_theme_mod('contact_email'), $subject,
'<!DOCTYPE html><html><head><title>' . $subject . '</title></head>' .
'<body>' .
'<p><b>Email:</b> ' . esc_html($my_email) . '</p>' .
'<p><b>Message:</b> ' . esc_html($my_text) . '</p>' .
'<hr />' .
'<small>This email was generated automatically using a form on the "www.speedment.com"-website.</small>' .
'</body></html>',
array(
'Content-Type: text/html; charset=UTF-8',
'From: speedment.com <[email protected]>',
"Reply-To: <$my_email>"
)
)) {
$my_email_error = "Error! Make sure specified address '$my_email' is correct.";
} else {
$my_success = true;
}
}
}
}
get_header(); ?>
<!-- Start Page Content -->
<div class="justify-content-center" id="contact">
<div class="container">
<!--
Contact Page Content
-->
<div class="row justify-content-center product-page">
<div class="col">
<!-- Start Page Content -->
<?php while (have_posts()) : the_post();
the_content();
endwhile; ?>
</div>
</div>
<!--
Contact Widget Area
-->
<div class="row justify-content-center product-page">
<div class="col-lg contact-form">
<h3>Contact Form</h3>
<p>Have a question? Need some information or a quote? Use the contact form below.</p>
<p><i>All fields marked * are required</i></p>
<?php if ($my_success) { ?>
<div class="row justify-content-center">
<div class="col">
<div class="alert alert-success" role="alert">
<strong>Thank you!</strong> Your message has been sent. We will get back to you as soon as we can.
</div>
</div>
</div>
<?php } else { ?>
<form action="?" method="POST">
<div class="row">
<div class="col-12">
<div class="form-group<?php if ($my_email_error) echo ' has-danger'; ?>">
<label for="myEmail">Email*</label>
<input name="myEmail" type="email" class="form-control<?php if ($my_email_error) echo ' form-control-danger'; ?>" id="myEmail" placeholder="Enter email address" value="<?php echo $my_email; ?>">
<?php if ($my_email_error) { ?><div class="form-control-feedback"><?php echo $my_email_error; ?></div><?php } ?>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="form-group">
<label for="myText">Message*</label>
<textarea name="myText" class="form-control" id="myText" rows="6" placeholder="Enter your message here..."><?php echo $my_text; ?></textarea>
</div>
</div>
</div>
<div class="form-group<?php if ($my_captcha_error) echo ' has-danger'; ?>">
<div class="g-recaptcha<?php if ($my_captcha_error) echo ' form-control-danger'; ?>" data-sitekey="<?php echo get_theme_mod('recaptcha_sitekey'); ?>"></div>
<?php if ($my_captcha_error) { ?><div class="form-control-feedback"><?php echo $my_captcha_error; ?></div><?php } ?>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<?php } ?>
</div>
<div class="col-lg-4 mb-4 mt-4 mt-lg-0">
<h3>Technical Questions</h3>
<p>If you have a technical question, one of our developers will be happy to assist you.
You can get in direct contact with them in our Gitter Chatroom.</p>
<img src="https://speedment.com/wp-content/uploads/2019/06/gitter_logo.png" width="30px"><a href="https://gitter.im/speedment/speedment" target="_blank"><h5>gitter.im/speedment</h5></a>
</div>
</div>
</div>
</div>
<!-- Start Page Content -->
<?php get_footer(); ?>