This repository was archived by the owner on Aug 27, 2022. It is now read-only.
forked from andreknieriem/photobooth
-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathsendPic.php
More file actions
93 lines (75 loc) · 2.25 KB
/
sendPic.php
File metadata and controls
93 lines (75 loc) · 2.25 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
<?php
header('Content-Type: application/json');
use PHPMailer\PHPMailer\PHPMailer;
require '../vendor/PHPMailer/src/Exception.php';
require '../vendor/PHPMailer/src/PHPMailer.php';
require '../vendor/PHPMailer/src/SMTP.php';
require_once('../lib/config.php');
require_once('../lib/db.php');
if (empty($_POST['sendTo']) || empty($_POST['image']) || !PHPMailer::validateAddress($_POST['sendTo'])) {
die(json_encode([
'success' => false,
'error' => 'E-Mail address invalid'
]));
}
$postImage = basename($_POST['image']);
if (!isImageInDB($postImage)) {
die(json_encode([
'success' => false,
'error' => 'Image not found in database'
]));
}
$mail = new PHPMailer;
$mail->setLanguage($config['language'], '../vendor/PHPMailer/language/');
$mail->isSMTP();
$mail->Host = $config['mail_host'];
$mail->SMTPAuth = true;
$mail->SMTPDebug = 0;
$mail->Username = $config['mail_username'];
$mail->Password = $config['mail_password'];
$mail->SMTPSecure = $config['mail_secure'];
$mail->Port = $config['mail_port'];
$mail->setFrom($config['mail_fromAddress'], $config['mail_fromName']);
if (!$mail->addAddress($_POST['sendTo'])) {
die(json_encode([
'success' => false,
'error' => 'E-Mail address not valid / error'
]));
}
// Email subject
$mail->Subject = $config['mail_subject'];
// Email body content
$mailContent = $config['mail_text'];
// for send an attachment
$path = $config['foldersAbs']['images'] . DIRECTORY_SEPARATOR;
$mail->Body = $mailContent;
if (!$mail->addAttachment($path . $postImage)) {
die(json_encode([
'success' => false,
'error' => 'file error:' . $path . $postImage
]));
}
if (isset($_POST['send-link']) && $_POST['send-link'] === 'yes') {
if (!file_exists(MAIL_FILE)) {
$addresses = [];
} else {
$addresses = json_decode(file_get_contents(MAIL_FILE));
}
if (!in_array($_POST['sendTo'], $addresses)) {
$addresses[] = $_POST['sendTo'];
}
file_put_contents(MAIL_FILE, json_encode($addresses));
die(json_encode([
'success' => true,
'saved' => true
]));
}
if ($mail->send()) {
die(json_encode([
'success' => true,
]));
}
die(json_encode([
'success' => false,
'error' => $mail->ErrorInfo
]));