· 5 years ago · Feb 04, 2020, 10:28 PM
1<?php
2
3require "config/config.php"; //include config file
4
5// GOOGLE GOODNESS
6
7 if(isset($_POST['submit'])){
8
9 $userIP = $_SERVER["REMOTE_ADDR"];
10
11 $recaptchaResponse = $_POST['g-recaptcha-response'];
12
13 $secretKey = $yoursecretkey;
14
15 $request = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secretKey}&response={$recaptchaResponse}&remoteip={$userIP}");
16
17
18
19 if(!strstr($request, "true")){
20
21 echo '<div class="alert alert-danger" role="alert"><strong>Błąd!</strong>Problem z weryfikacja Captcha, proszę wypełnić jescze raz :)</div>';
22
23 }
24
25 else{
26
27 // echo "WORKS MOTHERFUCKER CONGRATS!";
28
29 if(isset($_POST['submit']))
30
31 {
32
33
34
35 $message=
36
37 'Imię i Nazwisko: '.$_POST['fullname'].'<br />
38
39 Temat: '.$_POST['subject'].'<br />
40
41 Numer Telefonu: '.$_POST['phone'].'<br />
42
43 Email: '.$_POST['emailid'].'<br />
44
45 Wiadomość: '.$_POST['comments'].'<br />
46
47 ';
48
49 require "PHPMailer-master/class.phpmailer.php"; //include phpmailer class
50
51
52
53
54
55 // Instantiate Class
56
57 $mail = new PHPMailer();
58
59
60
61 // Set up SMTP
62
63 $mail->IsSMTP(); // Sets up a SMTP connection
64
65 $mail->SMTPAuth = true; // Connection with the SMTP does require authorization
66
67 $mail->SMTPSecure = "tls"; // Connect using a TLS connection
68
69 $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
70
71 $mail->Port = 587; //Gmail SMTP port
72
73 $mail->Encoding = '7bit';
74
75
76
77 // Authentication
78
79 $mail->Username = "kulas.stolarz@gmail.com"; // Your full Gmail address
80
81 $mail->Password = ""; // Your Gmail password
82
83
84
85 // Compose
86
87 $mail->SetFrom($_POST['emailid'], $_POST['fullname']);
88
89 $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
90
91 $mail->Subject = "Formularz kontaktowy ze strony"; // Subject (which isn't required)
92
93 $mail->Attach = "Zdjecie";
94
95 if (isset($_FILES['attach']) && $_FILES['attach']['error'] == UPLOAD_ERR_OK)
96
97 {
98
99 $mail->AddAttachment($_FILES['attach']['tmp_name'], $_FILES['attach']['name']);
100
101 }
102
103 $mail->MsgHTML($message);
104
105
106
107 // Send To
108
109 $mail->AddAddress($receiverEmail, $receiverName); // Where to send it - Recipient
110
111 $result = $mail->Send(); // Send!
112
113 if ($result) {
114 echo "wyslano"; // Send!
115 } else {
116 echo "error" . $mail->ErrorInfo;
117 }
118
119 ini_set('display_errors', 1);
120 ini_set('display_startup_errors', 1);
121 error_reporting(E_ALL);
122
123 $message = $mail->ErrorInfo; //. $result ? '<div class="alert alert-success" role="alert"><strong>Sukces!</strong>Wiadomość została wsyłana pomyślnie!</div>' : '<div class="alert alert-danger" role="alert"><strong>Błąd!</strong>Problem z dostarczeniem wiadomości. Proszę wypełnić jeszcze raz</div>';
124
125
126
127 unset($mail);
128
129
130
131
132
133
134
135 }
136
137 }
138
139 }
140
141
142
143?>
144
145
146
147<script>
148
149function sprawdz(formularz)
150
151{
152
153 for (i = 0; i < formularz.length; i++)
154
155 {
156
157 var pole = formularz.elements[i];
158
159 if (!pole.disabled && !pole.readonly && (pole.type == "text" || pole.type == "email" || pole.type == "textarea") && pole.value == "")
160
161 {
162
163 alert("Proszę wypełnić wszystkie pola!");
164
165 return false;
166
167 }
168
169 }
170
171 return true;
172
173}
174
175</script>
176
177
178
179<!DOCTYPE html>
180
181<html lang="en">
182
183 <head>
184
185 <meta charset="utf-8">
186
187 <meta http-equiv="X-UA-Compatible" content="IE=edge">
188
189 <meta name="viewport" content="width=device-width, initial-scale=1">
190
191 <link rel="icon" type="image/png" href="/images/favicon.png" sizes="16x16" />
192
193 <title>Kulas Stolarz - napisz do nas</title>
194
195
196
197 <!-- Bootstrap -->
198
199 <link href="css/bootstrap.min.css" rel="stylesheet">
200
201 <link rel="stylesheet" href="css/style.css">
202
203
204
205 <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
206
207 <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
208
209 <!--[if lt IE 9]>
210
211 <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
212
213 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
214
215 <![endif]-->
216
217 <script src='https://www.google.com/recaptcha/api.js'></script>
218
219 </head>
220
221 <body>
222
223 <div class="contactform">
224
225 <div class="panel panel-default">
226
227 <div class="panel-heading">
228
229 <h3 class="panel-title"><a href="">Napisz do nas</a></h3>
230
231 </div>
232
233 <div class="panel-body">
234
235 <form name="form1" id="form1" action="" method="post" enctype="multipart/form-data" onsubmit="if (sprawdz(this)) return true; return false"/>
236
237 <fieldset>
238
239 <input type="text" class="form-control" name="fullname" placeholder="Imię i Nazwisko (Wymagane)" />
240
241 <br />
242
243 <input type="text" class="form-control" name="subject" placeholder="Temat (Wymagane)" />
244
245 <br />
246
247 <input type="number" class="form-control" name="phone" placeholder="Numer Telefonu" />
248
249 <br />
250
251 <input type="email" class="form-control" name="emailid" placeholder="Email (Wymagane)" />
252
253 <br />
254
255 <textarea rows="4" class="form-control" cols="20" name="comments" placeholder="Wiadomość (Wymagane)"></textarea>
256
257 <br />
258
259 <label class="control-label" for="attach">Załącznik</label>
260
261 <input type="file" name="attach" id="attach" accept="image/*"/>
262
263 <?php
264
265 echo '<div class="g-recaptcha" data-sitekey="'.$yourpublickey.'"></div>';
266
267 ?>
268
269 <input type="submit" class="btn btn-lg btn-success button"name="submit" value="Wyślij wiadomość" />
270
271
272
273 </fieldset>
274
275 </form>
276
277 <p><?php if(!empty($message)) echo $message; ?></p>
278
279 </div>
280
281 </div>
282
283 </div>
284
285 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
286
287 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
288
289 <!-- Include all compiled plugins (below), or include individual files as needed -->
290
291 <script src="js/bootstrap.min.js"></script>
292
293 </body>
294
295</html>