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