This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
filespread/res/php/sendmail.php

68 lines
1.2 KiB
PHP
Raw Normal View History

2016-04-06 17:30:05 +02:00
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
2016-11-12 17:46:40 +01:00
$ini = parse_ini_file("../../filespread.ini");
2016-04-06 17:30:05 +02:00
date_default_timezone_set($ini["timezone"]);
require '../../vendor/autoload.php';
function main($ini) {
2016-04-06 17:30:05 +02:00
$data = json_decode($_GET["data"], true);
2016-04-06 17:30:05 +02:00
$list = "../../lists/" . $data["list"];
$addresses = file($list);
2016-04-06 17:30:05 +02:00
$content = $data["body"];
2016-04-06 17:30:05 +02:00
$title = $data["title"];
2016-04-06 17:30:05 +02:00
$filename = $data["filename"];
2016-04-06 17:30:05 +02:00
2017-04-20 13:32:09 +02:00
$nofile = $data["nofile"];
if ($nofile) {
$filename = "";
}
foreach ($addresses as $address) {
if (sendMail($title, $content, $filename, $address, $ini) != 0) {
print "-1";
exit;
}
}
2016-04-06 17:30:05 +02:00
print "0";
2016-04-06 17:30:05 +02:00
}
function sendMail($title, $content, $filename, $address, $ini) {
$mail = new PHPMailer;
2016-04-06 17:30:05 +02:00
$mail->setFrom($ini["email"], $ini["name"]);
$mail->Subject = $title;
$mail->Body = $content;
$mail->addAddress($address);
if (isset($ini["reply"])) {
$mail->addReplyTo($ini["reply"]);
2016-04-06 17:30:05 +02:00
}
2017-04-20 13:32:09 +02:00
if (!empty($filename)) {
$mail->AddAttachment("../../assets/file.bin", $filename);
}
if (!$mail->Send()) {
return -1;
} else {
return 0;
}
2016-04-06 17:30:05 +02:00
}
main($ini);