-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendmail.php
65 lines (54 loc) · 1.8 KB
/
sendmail.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
<?php
if (!isset($_POST['entries'])) exit(255);
$data = unserialize($_POST['entries']);
ini_set('display_errors', 'Off');
$ini = parse_ini_file('LDAP-IMAPExplorer.conf', true);
$from= $ini['email']['from'];
$mail_from = $ini['email']['mail_from'];
$reply_to = $ini['email']['reply_to'];
$allowed_domain = $ini['email']['allowed_domain'];
$syslog = $ini['syslog'];
require_once('functions.php');
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$user = username();
$err = NULL;
openlog($syslog['tag'], LOG_PID, $syslog['fac']);
clientIP($user);
if (PHP_SAPI != "cli") {
if(!filter_var($_POST['mailto'], FILTER_VALIDATE_EMAIL))
exit ($err = sprintf('<p>%s</p>',htmlentities("The email <{$_POST['mailto']}> is not valid.")));
else
if (explode('@',$_POST['mailto'])[1] != $allowed_domain)
exit ($err= sprintf('<p>%s</p>',htmlentities("You can send mail only to domain <$allowed_domain>. Email not sent.")));
}
if (!is_null($err))
syslog(LOG_ERR, "$user: $err");
$date = new DateTime('now');
$today = $date->format(DATE_RFC850);
$infoenv = "Generated on $today by LDAP&IMAP Explorer.";
$opt=$data[1];
$data[1] = $data[1]['retattr'];
$sheet= composeXLS($data);
$writer = createWriter($sheet);
$filename = saveXLS($writer, 'file');
$mailopt = array(
'mailfrom' => $mail_from,
'from' => $from,
'mailto' => $_POST['mailto'],
'reply' => $reply_to,
'prio' => 1,
'infoenv' => $infoenv,
'attachment' => $filename
);
$sent = emailSent ($opt,'Your LDAP&IMAP Explorer result',$mailopt);
if ($sent) {
$notice = sprintf ('Email successfully sent to "%s".', $mailopt['mailto']);
syslog(LOG_INFO, "$user: $notice");
}
else
$notice = 'Some errors occurred. Email could not be sent.';
printf ('<p>%s</p>',htmlentities($notice));
unlink ('tmp/'.$filename);
?>