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
Marcel Kapfer (mmk2410) a3c02b057d Mails send separatly. Input text used.
Res T123,T124
2016-11-20 08:47:12 +01:00

59 lines
1.1 KiB
PHP
Executable file

<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$ini = parse_ini_file("../../filespread.ini");
date_default_timezone_set($ini["timezone"]);
require '../../vendor/autoload.php';
function main($ini) {
$data = json_decode($_GET["data"], true);
$list = "../../lists/" . $data["list"];
$addresses = file($list);
$content = $data["body"];
$title = $data["title"];
$filename = $data["filename"];
foreach ($addresses as $address) {
if (sendMail($title, $content, $filename, $address, $ini) != 0) {
print "-1";
exit;
}
}
print "0";
}
function sendMail($title, $content, $filename, $address, $ini) {
$mail = new PHPMailer;
$mail->setFrom($ini["email"], $ini["name"]);
$mail->Subject = $title;
$mail->Body = $content;
$mail->addAddress($address);
if (isset($ini["reply"])) {
$mail->addReplyTo($ini["reply"]);
}
$mail->AddAttachment("../../assets/file.bin", $filename);
if (!$mail->Send()) {
return -1;
} else {
return 0;
}
}
main($ini);