-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmailer.php
More file actions
500 lines (435 loc) · 16.4 KB
/
mailer.php
File metadata and controls
500 lines (435 loc) · 16.4 KB
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<style>
</style>
<?php
session_start();
ob_start();
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//required files
require 'PHPMailer-master/PHPMailer-master/src/Exception.php';
require 'PHPMailer-master/PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/PHPMailer-master/src/SMTP.php';
//Create an instance; passing `true` enables exceptions
if (isset($_POST["sendmail"]) && isset($_SESSION['giohang'])) {
$mail = new PHPMailer(true);
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->CharSet = "utf-8";
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'zstyleshopvn@gmail.com'; //SMTP write your email
$mail->Password = 'sxdl zwmw frep mzwh'; //SMTP password
$mail->SMTPSecure = 'ssl'; //Enable implicit SSL encryption
$mail->Port = 465;
//Recipients
$mail->setFrom('zstyleshopvn@gmail.com', 'ZStyle' ); // Sender Email and name
$mail->addAddress($_POST["emaildat"], $_POST["tendat"]); //Add a recipient email // reply to sender email
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Cảm ơn bạn đã mua hàng cùng chúng tôi!'; // email subject headings
$mail->AddEmbeddedImage('view/layout/assets/images/logo-form.png', 'logo', 'logo-form.png');
$mail->AddEmbeddedImage('upload/form-thanks.jpg', 'img', 'form-thanks.jpg');
$i=0;
$tongtien=0;
$html_donhang='';
foreach ($_SESSION['giohang'] as $item) {
$i++;
extract($item);
$html_donhang.='<tr>
<td>'.$i.'</td>
<td>'.$name.'</td>
<td>'.$size.'</td>
<td>'.$color.'</td>
<td>'.number_format($price,0,'.',',').'</td>
<td>'.$soluong.'</td>
<td>'.number_format($price*$soluong,0,'.',',').'</td>
</tr>';
$tongtien+=$price*$soluong;
}
if(isset($_SESSION['giamgia']) && $_SESSION['giamgia']>0){
$giamgia=$_SESSION['giamgia'];
$html_donhang.='<tr>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td>Giảm giá</td>
<td>'.number_format(($tongtien*$giamgia/100),0,'.',',').'</td>
</tr>';
$html_donhang.='<tr>
<td class="td-trong" colspan="5"></td>
<td>Tổng tiền</td>
<td>'.number_format(($tongtien-$tongtien*$giamgia/100),0,'.',',').'</td>
</tr>';
unset($_SESSION['giamgia']);
}else{
$html_donhang.='<tr>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td class="td-trong"></td>
<td><strong>Tổng tiền</strong></td>
<td>'.number_format($tongtien,0,'.',',').'</td>
</tr>';
unset($_SESSION['giamgia']);
}
$account='';
if(isset($_SESSION['username']) && $_SESSION['username'] && isset($_SESSION['password']) && $_SESSION['password']){
$account='<tbody>
<td colspan="2" style="text-align:left"><strong>Username</strong> </td>
<td colspan="6" style="text-align:left">'.$_SESSION['username'].'</td>
</tbody>
<tbody>
<td colspan="2" style="text-align:left"><strong>Password</strong> </td>
<td colspan="6" style="text-align:left"> '.$_SESSION['password'].'</td>
</tbody>';
}
unset($_SESSION['id_voucher']);
unset($_SESSION['giamgia']);
unset($_SESSION['btngiamgia']);
unset($_SESSION['magiamgia']);
unset($_SESSION['giohang']);
// $noidung = file_get_contents("form_thank.php");
$text= '<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.title{
text-align: center;
color: #46694F;
}
.thank{
text-align: center;
}
table {
border-collapse: collapse;
width: 100%;
margin: 20px 0;
}
th{
background-color: #46694F;
color: #fff;
text-align: center;
}
tr{
text-align: center;
}
thead{
text-align: center;
}
th, td {
border: 1px solid #dddddd;
text-align:center;
padding: 8px;
}
tbody>td{
text-align: left;
}
</style>
</head>
<body>
<div class="container-form">
<img src="cid:logo" alt="ZStyle Logo" style="display: block; width: 150px; margin: 0 auto;">
<hr>
<h2 class="title">THÔNG TIN ĐƠN HÀNG</h2>
<p class="thank">Cảm ơn bạn đã ghé thăm cửa hàng của chúng tôi và đặt hàng tại đây!</p>
<table>
<thead>
<tr >
<th colspan="8"><p style="font-size: 16px;text-align: center"><strong>Mã đơn hàng:</strong> '.$_SESSION['donhang']['ma_donhang'].' </th>
</tr>
</thead>
<tbody>
<td colspan="2" style="text-align:left"><strong>Ngày lập</strong></td>
<td colspan="6" style="text-align:left">'.$_SESSION['ngaylap'].'</td>
</tbody>
<tbody>
<td colspan="2" style="text-align:left"><strong>Họ tên</strong></td>
<td colspan="6" style="text-align:left">'.$_SESSION['name'].'</td>
</tbody>
<tbody>
<td colspan="2" style="text-align:left"><strong>Email</strong></td>
<td colspan="6" style="text-align:left">'.$_SESSION['email'].'</td>
</tbody>
<tbody>
<td colspan="2" style="text-align:left"><strong>Số điện thoại</strong></td>
<td colspan="6" style="text-align:left">'.$_SESSION['sdt'].'</td>
</tbody>
<tbody>
<td colspan="2" style="text-align:left"><strong>Địa chỉ</strong></td>
<td colspan="6" style="text-align:left">'.$_SESSION['diachi'].'</td>
</tbody>
'.$account.'
<thead>
<tr>
<th>STT</th>
<th>Tên sản phẩm</th>
<th>Size</th>
<th>Màu sắc</th>
<th>Giá</th>
<th>Số lượng</th>
<th>Thành tiền</th>
</tr>
</thead>
<tbody>
'.$html_donhang.'
</tbody>
</table>
Chúng tôi mong sớm được gặp lại bạn.
<br>
Trân trọng, <strong>Zstyle</strong>
<hr>
<div class="icon">
<i class="fa-brands fa-facebook"></i>
<i class="fa-brands fa-instagram"></i>
<i class="fa-brands fa-google"></i>
<i class="fa-brands fa-shopify"></i>
</div>
ZStyle Shop <br>
Website: https://zstyle.online/ <br>
Địa chỉ: Tầng 12, tòa T, Công viên phần mềm Quang Trung <br>
Email: zstyleshopvn@gmail.com <br>
Hotline: 19006789 <br>
</div>
</body>
</html>';
unset($_SESSION['donhang']);
unset($_SESSION['name']);
unset($_SESSION['sdt']);
unset($_SESSION['diachi']);
unset($_SESSION['email']);
$mail->Body=$text;//email message
// Success sent message alert
$mail->send();
echo
"
<script>
document.location.href = 'index.php?pg=account';
</script>
";
}
function creatcode() {
$code='';
$characters = '0123456789';
for ($i = 0; $i < 4; $i++) {
$code .= $characters[mt_rand(0, strlen($characters) - 1)];
}
return $code;
}
function pdo_get_connection(){
$dburl = "mysql:host=localhost;dbname=zstyle;charset=utf8";
$username = 'root';
$password = '';
$conn = new PDO($dburl, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
}
function pdo_query($sql){
$sql_args = array_slice(func_get_args(), 1);
try{
$conn = pdo_get_connection();
$stmt = $conn->prepare($sql);
$stmt->execute($sql_args);
$rows = $stmt->fetchAll();
return $rows;
}
catch(PDOException $e){
throw $e;
}
finally{
unset($conn);
}
}
function pdo_query_one($sql){
$sql_args = array_slice(func_get_args(), 1);
try{
$conn = pdo_get_connection();
$stmt = $conn->prepare($sql);
$stmt->execute($sql_args);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row;
}
catch(PDOException $e){
throw $e;
}
finally{
unset($conn);
}
}
function getusertoemail($email){
$sql="SELECT * FROM users WHERE email=?";
return pdo_query_one($sql, $email);
}
if (isset($_POST["guima"])) {
$_SESSION['erremailxn']='';
$_SESSION['emailxn']=$_POST["emailxn"];
if($_POST['emailxn']==''){
$_SESSION['erremailxn']='*Bạn chưa nhập email';
}else{
if(!filter_var($_POST['emailxn'], FILTER_VALIDATE_EMAIL)){
$_SESSION['erremailxn']="*Địa chỉ email không hợp lệ";
}else{
$kt=0;
foreach ($_SESSION['usertable'] as $item) {
if($item['email']==$_POST['emailxn']){
$kt=1;
break;
}
}
if($kt==0){
$_SESSION['erremailxn']='*Địa chỉ email không tồn tại';
}
}
}
if($_SESSION['erremailxn']!=''){
echo
"
<script>
document.location.href = 'index.php?pg=forgetpass';
</script>
";
}else{
$mail = new PHPMailer(true);
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->CharSet = "utf-8";
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'myhong11a32004@gmail.com'; //SMTP write your email
$mail->Password = 'zhuv uzbw gnrd ziop'; //SMTP password
$mail->SMTPSecure = 'ssl'; //Enable implicit SSL encryption
$mail->Port = 465;
//Recipients
$mail->setFrom('zstyleshopvn@gmail.com', 'ZStyle' ); // Sender Email and name
$mail->addAddress($_POST["emailxn"]); //Add a recipient email // reply to sender email
$_SESSION['emailxn']=$_POST["emailxn"];
$_SESSION['username']=getusertoemail($_SESSION['emailxn'])['user'];
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Chúng tôi đã khôi phục thành công tài khoản cho bạn!'; // email subject headings
$mail->AddEmbeddedImage('view/layout/assets/images/logo-form.png', 'logo', 'logo-form.png');
$_SESSION['code']=creatcode();
// $noidung = file_get_contents("form_thank.php");
$text= '<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://kit.fontawesome.com/945522403a.js" crossorigin="anonymous"></script>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
max-width: 600px;
margin: 0 auto;
}
.container>img{
display: block;
margin: 0 auto;
color: black;
width: 100px;
}
p {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th{
background-color: #46694F;
color: #fff;
}
th, td {
border: 1px solid #46694F;
text-align: left;
padding: 8px;
}
.title{
text-align:center;
font-size:18px;
color: #46694F;
}
.td-trong{
border:none;
}
.icon{
margin: 10px 0;
text-align: center;
}
.icon>i{
padding: 3px;
color: #46694F;
}
#code{
width: 80px;
margin: 0 auto;
padding: 10px 20px;
border: 3px solid #dddddd;
border-radius: 5px;
text-align: center;
font-weight: bold;
font-size: 28px;
color: #46694f;
}
h2{
text-align: center;
color: #46694f;
}
td{
width:50%;
}
</style>
</head>
<body>
<div class="container">
<img src="cid:logo" alt="ZStyle Logo" style="display: block; width: 150px; margin: 0 auto;">
<br>
<hr>
<h2>Chào mừng bạn trở lại!</h2>
<p class="text">Hãy sử dụng mã xác minh bên dưới để xác nhận tài khoản có thông tin</p>
<table>
<tbody>
<tr>
<td><strong>Email</strong> </td>
<td>'.$_SESSION['emailxn'].'</td>
</tr>
<tr>
<td><strong>Tên đăng nhập</strong></td>
<td>'.$_SESSION['username'].'</td>
</tr>
</tbody>
</table>
<div id="code">
'.$_SESSION['code'].'
</div>
Trân trọng, <strong>Zstyle</strong>
<hr>
ZStyle Shop <br>
Website: https://zstyle.online/ <br>
Địa chỉ: Tầng 12, tòa T, Công viên phần mềm Quang Trung <br>
Email: zstyleshopvn@gmail.com <br>
Hotline: 19006789 <br>
</div>
</body>
</html>';
$_SESSION['codedung']=$_SESSION['code'];
unset($_SESSION['code']);
$mail->Body=$text;//email message
// Success sent message alert
$mail->send();
echo
"
<script>
document.location.href = 'index.php?pg=forgetpass';
</script>
";
}
}