forked from robiso/contact-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact-form.php
250 lines (211 loc) · 9.5 KB
/
contact-form.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* Contact form plugin for WonderCMS.
*
* It allows to add and manage additional contents on a page.
*
* @author Thijs Ferket www.ferket.net
* @forked and adapted by Herman Adema
* @forked by Jeremy Czajkowski
* @forked by Robert Isoski @robiso
* @version 3.0.0
*/
global $Wcms;
if (defined('VERSION') && !defined('version')) {
define('version', VERSION);
defined('version') OR die('Direct access is not allowed.');
}
$configuration = parse_ini_file('config');
define('CONTACT_FORM_PAGE', $configuration ['page']);
define('CONTACT_FORM_EMAIL', $configuration ['emailAddress']);
define('CONTACT_FORM_LANG', $configuration ['language']);
define('CONTACT_FORM_RECAPTCHA_SITE_KEY', $configuration ['reCaptchaSiteKey']);
$Wcms->addListener('css', 'contactfCSS');
if (CONTACT_FORM_RECAPTCHA_SITE_KEY) {
$Wcms->addListener('js', 'recaptchaJS');
}
function contactfCSS($args) {
global $Wcms;
$script = '<link rel="stylesheet" href="'.$Wcms->url("plugins/contact-form/css/style.css").'" type="text/css">';
$args[0].=$script;
return $args;
}
function recaptchaJS($args) {
global $Wcms;
$script = '<script src="https://www.google.com/recaptcha/api.js?render='.CONTACT_FORM_RECAPTCHA_SITE_KEY.'"></script>';
$script .= '<script>
function onSubmit(token) {
document.getElementById("wonder-cms-form").submit();
}
</script>';
$args[0].=$script;
return $args;
}
function contactfCONTENT() {
global $Wcms;
$emailadr = CONTACT_FORM_EMAIL;
// Internationalization
$i18n = parse_ini_file('languages/'.CONTACT_FORM_LANG.'.ini');
// Config
$cfg['email'] = $emailadr; // Webmaster email
$cfg['text'] = TRUE; // If an error occurs, make text red ( TRUE is on, FALSE is off )
$cfg['input'] = TRUE; // If an error occurs, make border red ( TRUE is on, FALSE is off )
$cfg['HTML'] = FALSE; // HTML email ( TRUE is on, FALSE is off )
// Email validator
function checkmail($email) {
if(preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $email)) {
return TRUE;
}
return FALSE;
}
$formulier = TRUE;
$final_content = '';
if(isset($_POST['submitForm']) && ($_SERVER['REQUEST_METHOD'] == "POST")) {
$aFout = array();
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
if(empty($name) || (strlen($name) < 3) || preg_match("/([<>])/i", $name) ) {
$aFout[] = $i18n['name_empty'];
unset($name);
$fout['text']['name'] = TRUE;
$fout['input']['name'] = TRUE;
}
if(empty($email)) {
$aFout[] = $i18n['email_empty'];
unset($email);
$fout['text']['email'] = TRUE;
$fout['input']['email'] = TRUE;
} elseif(checkmail($email) == 0) {
$aFout[] = $i18n['email_invalid'];
unset($email);
$fout['text']['email'] = TRUE;
$fout['input']['email'] = TRUE;
}
if(empty($subject)) {
$aFout[] = $i18n['subject_empty'];
unset($subject);
$fout['text']['subject'] = TRUE;
$fout['input']['subject'] = TRUE;
}
if(empty($message)) {
$aFout[] = $i18n['message_empty'];
unset($message);
$fout['text']['message'] = TRUE;
$fout['input']['message'] = TRUE;
}
if(!$cfg['text']) {
unset($fout['text']);
}
if(!$cfg['input']) {
unset($fout['input']);
}
if(empty( $aFout )) {
$formulier = FALSE;
if($cfg['HTML']) {
// Headers
$headers = "From: ".$cfg['email']."\r\n";
$headers .= "Reply-To: \"".$name."\" <".$email.">\n";
$headers .= "Return-Path: Mail-Error <".$cfg['email'].">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$message = '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>
<body>
<br />
<b>Name:</b> '.$name.'<br /><br />
<b>Email:</b> '.$email.'<br /><br />
<br />
<b>Message:</b><br /><br />
'.$message.'
<br />
<br />
<br />
--------------------------------------------------------------------------<br />
<b>IP:</b> '.$_SERVER['REMOTE_ADDR'].'<br />
</body>
</html>';
} else {
$message_wrap = wordwrap ($message, 40, "\n", 1);
// Headers
$headers = "From: \"".$Wcms->get('config','siteTitle')."\" <$cfg[email]>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset='utf-8'\n";
// message
$message = "Name: ".$name." \n\n";
$message .= "Email: ".$email." \n\n";
$message .= "Message:\n".$message_wrap." \n";
$message .= " \n ";
$message .= "------------------------------------------------------- \n ";
$message .= "IP: ".$_SERVER['REMOTE_ADDR']." \n ";
}
if(mail($cfg['email'], $i18n['subject_prefix']." ".$subject, $message, $headers)) {
$headers = "From: ".$cfg['email']."\r\n";
$headers .= "Reply-To: \"".$cfg['email']."\" <".$cfg['email'].">\n";
$headers .= "Return-Path: Mail-Error <".$email.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$sent = true;
unset($name, $email, $subject, $message);
}
else {
$sent = false;
}
// header ('Location: ' . $_SERVER['REQUEST_URI']);
if ($sent) {
echo "<h4 class='text-center'<br /><br />" . $i18n['result_sent'] . "</h4>";
} else {
echo "<h4 class='text-center'><br /><br />" . $i18n['result_failed'] . "</h4>";
}
}
}
if($formulier) {
$final_content .= "<div id='message'><p class='message'>" . ($_SESSION['SubmitMessage'] ?? '') . "</p></div>";
unset($_SESSION['SubmitMessage']);
if($aFout ?? false) {
$final_content .= '<div id="errors">' . implode('<br>' ,$aFout) . '</div>';
}
$final_content .= "<div id='containerform'>";
$final_content .= "<form id='wonder-cms-form' method='post' action=''>";
$final_content .= "<p>";
$final_content .= "<div class='form-group'><input type='text' placeholder='$i18n[name]' id='name' name='name' maxlength='30'";
if(isset($fout['input']['name'])) { $final_content .= "class='fout'"; } $final_content .= "value='";
if (!empty($name)) { $final_content .= stripslashes($name); } $final_content .= "' /></div>";
$final_content .= "<div class='form-group'><input type='text' placeholder='$i18n[email]' id='email' name='email' maxlength='255'";
if(isset($fout['input']['email'])) { $final_content .= "class='fout'"; } $final_content .= "value='";
if (!empty($email)) { $final_content .= stripslashes($email); } $final_content .= "' /></div>";
$final_content .= "<div class='form-group'><input type='text' placeholder='$i18n[subject]' id='subject' name='subject' maxlength='40'";
if(isset($fout['input']['subject'])) { $final_content .= "class='fout'"; } $final_content .= "value='";
if (!empty($subject)) { $final_content .= stripslashes($subject); } $final_content .= "' /></div>";
$final_content .= "<div class='form-group'><textarea placeholder='$i18n[message]' id='message' name='message'";
if(isset($fout['input']['message'])) { $final_content .= "class='fout'"; } $final_content .= " cols='31' rows='10'>";
if (!empty($message)) { $final_content .= stripslashes($message); } $final_content .= "</textarea></div>";
$recaptcha_btn_attr = ' ';
if (CONTACT_FORM_RECAPTCHA_SITE_KEY) {
$recaptcha_btn_attr = "data-sitekey='".CONTACT_FORM_RECAPTCHA_SITE_KEY."' data-callback='onSubmit' data-action='submit'";
}
$final_content .= "<input type='submit' id='submitForm' class='btn btn-primary btn-block' name='submitForm' value='$i18n[submit]' ".$recaptcha_btn_attr." />";
$final_content .= "</p>";
$final_content .= "</form>";
$final_content .= "</div>";
}
return $final_content;
}
function contact_form() {
global $Wcms;
$result = '';
if ($Wcms->currentPage == CONTACT_FORM_PAGE) {
$result .= '<div class="container marginTop20"><div class="col-xs-12 col-md-6 col-md-offset-3">';
$result .= '<div id="contactform" class="grayFont">';
$result .= contactfCONTENT();
$result .= '</div></div></div>';
}
return $result;
}
?>